[clean-list] God must be programming in Clean

katayama@ikura.fe.dis.titech.ac.jp katayama@ikura.fe.dis.titech.ac.jp
9 Aug 2001 17:41:45 -0000


That's really amazing. How can it happen to such a small code?

I also compared them (C++ and Clean codes) on Red Hat Linux 7.1 on i686 and 
Windows98 with Cygwin on Celeron. 
Well, I am thinking what was wrong with my way of comparison,
because purely functional code beat the C code in speed.

<Linux case>

(compiled with CleanIDE)
rts[~/LangComp]:time cosx
1.5707963267949
1.170u 0.010s 0:01.17 100.8%    0+0k 0+0io 248pf+0w

rts[~/LangComp]:gcc -O2 -lm -o cosxGCCO2 cosx.c
rts[~/LangComp]:time cosxGCCO2 
cosx: 1.570796
1.410u 0.010s 0:01.41 100.7%    0+0k 0+0io 113pf+0w

rts[~/LangComp]:gcc -O6 -lm -o cosxGCCO6 cosx.c
rts[~/LangComp]:time cosxGCCO6
cosx: 1.570796
1.410u 0.000s 0:01.40 100.7%    0+0k 0+0io 113pf+0w

<Windows case>

(compiled with CleanIDE and entered Cygwin)
$ time cosx.exe
1.570796

real    0m3.240s
user    0m0.000s
sys     0m0.000s

$ gcc -O2 -o cosxGCCO2.exe cosx.c

$ time cosxGCCO2.exe
cosx: 1.570796

real    0m5.820s
user    0m0.000s
sys     0m0.000s

$ gcc -O6 -o cosxGCCO6.exe cosx.c

$ time cosxGCCO6.exe
cosx: 1.570796

real    0m5.710s
user    0m0.000s
sys     0m0.000s

I hope this result helps me to pursuade my boss to abandon all the C++ codes.

- Susumu Katayama


FYI, the following is a Haskell translation and its result on Windows98 
with GHC4.08.
The result is within my expectation because ghc on Windows compiles via 
gcc.

\begin{code}
test :: Int -> Double -> Double
test n cosx
        | n==0 = cosx
        | otherwise = test (n-1) (cosx+cos(cosx))

main = print (test 10000000 0.0)
\end{code}

$ ghc-4.08.2 -O -o cosxGHC.exe cosx.lhs

$ time cosxGHC.exe
1.5707963267948966

real    0m7.580s
user    0m0.000s
sys     0m0.000s