# Mini benchmark.

• To: clisp-list@ma2s2.mathematik.uni-karlsruhe.de
• Subject: Mini benchmark.
• From: "John Carter" <ECE@dwaf-hri.pwv.gov.za>
• Date: Thu, 26 Oct 1995 09:14:55 +0200
• Organization: Dpt Water Affairs & Forestry (IWQS)
• Priority: normal

```Greetings All,

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).
2) It is dead simple. So simple it can be translated in 30 seconds
to any language you choose.
3) It cannot be optimised away entirely.
4) You can see immediately if you got the right answer.

Here it is in C or C++...
#include <stdio.h>

main( int argc, char * argv[])
{
int n;
double x, y;

sscanf( argv[ 1], "%d", &n);
x = 1.0;
y = 1.0 + 1.0 / n;

for( int i=0; i < n; i++)
x *= y;

printf( "y=%lf, x=%lf\n", y, x);
}

Here it is QBasic...
INPUT "n?"; n
x = 1
y = 1 + 1 / n
FOR i = 1 TO n
x = x * y
NEXT i
PRINT "y="; y; " x="; x

Here it is in AWK...
{
n=\$1
x = 1.0
y = 1.0 + 1.0 / n
for( i=0; i<n; i++)
x *= y
print "y=", y, " x=", x
}

Here it is in Actor...
n := 100000L
y := 1.0 + 1.0 / n
x := 1.0
loop
while n > 0
begin
x := x * y;
n := n - 1;
endLoop;
print( "y=");
print( y);
print( " x=");
print( x);

And finally, the point of this whole message, in Lisp...
(defun test (n)
(let ((x 1.0) (y (+ 1 (/ 1.0 n))))
(dotimes (i n)
(setf x (* x y)))
(print y)
(print x)))

According to my tests I rank languages like so..
Interpreted Emacs lisp and Clisp
Qbasic.
Awk, Actor and MS-Excel Visual Basic
Compiled CLISP
Compiled EMACS Lisp
GNU C++ (33 times faster than Emacs lisp and 170x faster than Actor)

Now I may be doing something silly in Lisp (I'm not "at home" with
it), can the readers please rewrite the lisp code to run as fast as
possible. (All speed optimization flags on).

This may be a VERY VERY crude benchmark, but it gives a suprisingly
(given the crudeness) accurate reflection of the reality.

Thank you,

John Carter
Institute for Water Quality Studies. Department of Water Affairs.
Internet : ece@dwaf-hri.pwv.gov.za  Phone    : 27-12-808-0374x194
Fax : 27-12-808-0338 [Host for Afwater list server]

Founder of the Council for Unnatural Scientists.
```