[plt-scheme] Experience Using Mz(Dr)Scheme for Numerical Work

From: Eli Barzilay (eli at barzilay.org)
Date: Sun Apr 17 17:00:51 EDT 2005

On Apr 17, Will M. Farr wrote:
> [...]
> Unfortunately, after writing the same simple integrators in C,
> common lisp, and scheme, I find that, even with a C-coded inner
> loop, DrScheme/MzScheme are about 10 times slower than SBCL, and 15
> times slower than straight C.  The difficulty seems to be that
> computing m1*m2/r12^2 isn't enough work to offset the baggage that
> comes with a FFI call, and the looping overhead.
> [...]

Yes, looping would be the computational bottleneck if you use Scheme
with lots of simple computations.  One thing to consider is to use
_fixnum if you know you'll never get bignums -- _fixnum uses a cheaper
translation when going to/from C.

Another thing that might be viable is to use bindings from something
like GSL -- using the foreign interface it is really simple to pull a
few functions out.  I don't know whether this can be a solution or not
since I don't know what an advanced integrator is -- and the same
holds for moving the loops on to C.  (If you want to do that, then it
is also simple to write straight C code and use foreign to interface

If there is no clear way to separate out some computation intensive
core out to C, then for now CL would be a better choice -- you could
in that case use one of the packages that allow porting simple code
from Scheme to CL, even if it results in incomprehensible Lisp code.
(You could use some Scheme macro for loops and translate that to Lisp
iterations.  With modules you will be stuck -- CL is much poorer in
that department.)

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!

Posted on the users mailing list.