[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Mini benchmark.
John Carter <ECE@dwaf-hri.pwv.gov.za> writes:
> I am contemplating writing some largish programs in CLISP. But before
> I commit myself to this I need a very rough idea of performance. I
> have this pet little bench mark which calculates e=2.71828... I like
> this benchmark because :-
> 1) It reflects floating point performance, (which I am
> most concerned with).
But you have to be careful to measure the performance with the same
kind of floating-point numbers.
> Here it is in C or C++...
> double x, y;
These are IEEE double-precision floats (53 mantissa bits).
> And finally, the point of this whole message, in Lisp...
> (defun test (n)
> (let ((x 1.0) (y (+ 1 (/ 1.0 n))))
These are, by default in Common Lisp, single-floats, i.e. (in CLISP)
IEEE single-precision floats (24 mantissa bits).
Giuseppe showed us declarations for short-floats (20 mantissa bits or so?).
You cannot directly compare timings of computations with different
kinds of floats.
> According to my tests I rank languages like so..
> Compiled CLISP
> Compiled EMACS Lisp
> GNU C++ (33 times faster than Emacs lisp and 170x faster than Actor)
Admittedly, CLISP's floating-point performance for single/double
floats is not good. (The Gabriel FFT benchmark shows this as well.)
But in CLISP, you can increase the precision of your floats as much as
you want, just by changing the *DEFAULT-FLOAT-FORMAT*,
*READ-DEFAULT-FLOAT-FORMAT* and (LONG-FLOAT-DIGITS) variables.
Say you want to compute e by its power series, like this:
(defun e (&optional (x 1.0))
(do* ((n 0 (1+ n))
(y (float 1 x) (/ (* y x) n))
(sum (float 0 x)))
((= sum (setf sum (+ sum y))) sum)
In CLISP you don't have to change your program _at_all_ if you want
to increase the precision of the result:
> (e 1.0L0)
> (e (float-digits 1 200))
(Of course, the built-in function EXP is still twice as fast than the
function E presented here.)
If this feature is not useful to you and you rely heavily on floating-
point performance, then you should try some other Lisps such as GCL or
(as Giuseppe pointed out) Ecolisp.
Bruno Haible email: <firstname.lastname@example.org>
Software Engineer phone: +33-1-49083585