[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
re: Scientific Computing
- To: firstname.lastname@example.org
- Subject: re: Scientific Computing
- From: email@example.com (Bob Hall)
- Date: Mon, 28 Sep 92 17:04:06 EDT
- Cc: firstname.lastname@example.org
- In-reply-to: Hans-Martin Adorf's message of Mon, 28 Sep 92 20:49:04 +0100 <9209281949.AA07687@ns3.hq.eso.org>
Regarding Lisp versus Fortran for scientific computing:
It is not surprising that Fortran beats Lisp, since it is a much lower
level language. Probably if you wrote in Assembler you'd go even
faster. The point is, though, that even in the scientific
computing world, most programs don't have to be as fast as possible,
since they are not the bottleneck. Thus, what that community probably
wants is to develop programs in Lisp, profile the programs to find
the bottlenecks, and if necessary code the hot spots in a low-level
alternative such as C or Fortran, using the foreign-function interface
to pass data back and forth. Note that this optimization is performed last
when the rest of the program already works. Both Franz and MCL have
FFIs. I don't know if *Lisp has this.
For your info, I ran the following two versions of the log-factorial
code on my IIfx (36Mb of memory, MCL 2.0 final). Note that the declarations
did make a factor of 2/3 difference in memory allocation
and a small speed difference. I expect that when the application gets
larger this will become more telling. I don't have fortran, so I couldn't
run your benchmark here. Note that the IIfx times beat your SE/30
times by a factor of about 2 1/2 (for the n=1000 case).
;;; Version with declarations:
(defun frob (n)
(declare (optimize (speed 3) (safety 0)))
(let* ((result 0.0))
(do ((k 1 (the integer (1+ (the integer k)))))
((> (the integer k) (the integer n)) result)
(the float (+ (the float result) (log (float (the integer k)))))))))
(time (frob 200)) ;;==> 863.2319871924054
;(FROB 200) took 23 milliseconds (0.023 seconds) to run.
; 4800 bytes of memory allocated.
(time (frob 1000)) ;;==> 5912.128178488171
;(FROB 1000) took 113 milliseconds (0.113 seconds) to run.
; 24000 bytes of memory allocated.
;;; Version without declarations
(defun frob-no-dec (n)
(let* ((result 0.0))
(do ((k 1 (1+ k)))
((> k n) result)
(+ result (log k))))))
(time (frob-no-dec 200)) ;;==> 863.2319871924054
;(FROB-NO-DEC 200) took 22 milliseconds (0.022 seconds) to run.
; 3200 bytes of memory allocated.
(time (frob-no-dec 1000)) ;;==> 5912.128178488171
;(FROB-NO-DEC 1000) took 109 milliseconds (0.109 seconds) to run.
; 16000 bytes of memory allocated.