[clean-list] God must be programming in Clean

Siegfried Gonzi siegfried.gonzi@kfunigraz.ac.at
Thu, 09 Aug 2001 10:33:13 +0200


[NOTICE: This message has been posted to comp.lang.functional and in
changed form to the Clean-mailinglist 
and in changed form also to comp.lang.lisp].


My heart is beating faster.

In com.lang.lisp someone posted a LISP code (please find the code at the
end of my post) and complaint that it is 10
times slower than a comparable C version on his machine. If the LISP
code (with all possible strict declarations) gets compiled (every modern
LISP development environment lets you compile to native code!) then it
is always 10 times slower. The LISP compiler is a commercial one (and
not that cheap!) from Franz Inc.

Someone posted that on his Unix the LISP (CMU-COMMON-LISP for Unix) code
has got the same execution  speed as the C version.

This should be not of great surprise because it is often said that LISP
can get 80% of the performance of C.


On my Mac there is PowerLisp 2.2 for the Mac installed. It is also
possible to compile to native PPC code. I also tried the posted LISP
code on my Mac. Not of great surprise that the compiled code is 5 times
faster than the interpreted LISP code.

But I also wanted to know how fast the C-code on my machine is. And to
my great surprise, it is also 10 
times faster than the compiled LISP code. Please find the C-code (double
or float is not of concern; they both deliver the same execution time)
at the end of my post.
 
Oh my God. Where are the famous 80% of C speed? Surely it is due to the
compiler implementation.


But my next turn has been a little Clean program. I really has been
fearing the result: will it show the same slow execution time as the
LISP version? No! The Clean version (double version only, because Clean
does only discern between 32bit Integer and 64bit Real) takes exactly
the same  execution time as the C version (compiled with the Macintosh
MPW native C/C++ compiler)!

My suggestions to the Clean team in order to promote Clean and make it
widespread popular:

a) Open your real windows and throw out all the pointless
Windows-licences and machines
b) Go to a local oracle-men and let you explain:
        bb) Concenrate on Macintosh, Linux/Unix and other user systems
only 
        cc) Think on god old days, drink a few beers, go into a
striptease bar but forget Microsoft
        
        

S. Gonzi (please notice the enclosed code for your evaluation of my
propositions; I am not interested in that fucking C/C++, therefore send
your complaints about my C coding-style to Plan9 or elsewhere)

---THE POSTED LISP CODE IN COMP.LANG.LISP:---
---execution: e.g. (test '1000000) ---

(defun test (n)
        (declare (optimize (speed 3) (safety 0))
                (fixnum n))
        (let ((x 0.0s0))
                (declare (single-float x))
                (dotimes (i n)
                        (incf x (the single-float (cos x))))
        x))

---My equivalent C version; I am not a LISP expert; but I think the C
version does the same as---
---the above LISP-code---

#include <stdio.h>
#include <math.h>
int main( void )
{
        int i;
        int n=10000000; /*The same 'n' as in the LISP-code; A big n is
easier for*/
                                        /*timing the execution time with
a watch*/
        double cosx=0.0; /*Use float here if you want; but this doesn't
influence*/
                                        /*the execution time, at least
on my Macintosh*/
        
        for(i=0;i<=n;i++)
        {
                cosx = cosx + cos(cosx);
        }
        printf("cosx: %f\n",cosx);
return 0;
}


---MY "STRICT" CLEAN VERSION---

module cosx
import StdEnv

test::!Int !Real -> !Real
test n cosx
        | n==0 = cosx
        | otherwise = test (n-1) (cosx+cos(cosx))
        
Start = test 10000000 0.0

---END OF THE ENLIGHTENMENT BROUGHT TO YOU BY THE FAMOUS MR. GONZI---