[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Number crunching in CLISP.

Bruno Haible writes:

I have to write some serious number crunching code, and I'd like to
write it in CLISP.  If my memory serves me correctly, Bruno once told
me that CLISP does all floating point operations by itself (i.e. -
doesn't use the FPU).  Is this correct?  If so, I won't be able to use
it.  If it does do floating point in software, how hard is it to
change this?  Are floating point numbers stored in system format (as a
C float)?  Is the numerical code well isolated?  If it doesn't use the
FPU & changing it would be difficult, then what about some other
common lisps - does anyone know about GCL & XLISP?  From the following
quick & simpleminded test, it seems that neither CLISP nor XLISP will
be suitable:

 ------------------ File test.lsp --------------------
(defvar i 1)
(time (dotimes (j 100000) (setq i (* i 1.00001))))
 ------------------End file test.lsp -----------------------

CLISP run (best of 3):

> (load "test.lsp")
;; Loading file test.lsp ...
Real time: 25.37575 sec.
Run time: 25.36 sec.
Space: 800456 Bytes
GC: 1, GC time: 0.28 sec.
;; Loading of file test.lsp is finished.

XLISPSTAT run (best of 3):

> (load "test.lsp")
; loading "test.lsp"
The evaluation took 19.40 seconds

CLISP run of compiled code (best of 3):
> (compile-file "test.lsp")

Compiling file /new/home/hjstein/test.lsp ...

Compilation of file /new/home/hjstein/test.lsp is finished.
0 errors, 0 warnings

   . . . 

> (load "test")
;; Loading file /new/home/hjstein/test.fas ...
Real time: 4.628368 sec.
Run time: 4.62 sec.
Space: 800000 Bytes
GC: 1, GC time: 0.28 sec.
;; Loading of file /new/home/hjstein/test.fas is finished.

I didn't run XLISPSTAT compiled because the compiler just came out & I
haven't picked it up yet.

Here's what I'd consider roughly equivalent C code, along with it's

  long j;
  double i;

  i = 1;
  for (j = 0; j < 1000000; j++) i = i * 1.00001;

hjstein:~$ time /home/hjstein/test
real        1.0
user        1.6
sys         0.0

All this is on a 486dx20 running Linux.

Since the C code is doing the loop 10x as many times as the lisp code
(I had to crank it up to measure it with the time command), it seems
that this C code is over 20 times faster than the compiled CLISP code.
If the CLISP was only twice as slow, or even only 5 times slower, I
could probably live with it for prototyping purposes (I have things
which run for hours on end).  So, how can I speed it up?


Harvey J. Stein
Berger Financial Research