lua-users home
lua-l archive

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


Hi,

a key argument for Lua is its speed compared to other GPL-ed languages. 

Here a little comparison I made on a Linux box with 200 MHz Pentium. The
first line tells the command
to invoke a dumb Fibonacci computation of 30, the second line gives the
execution time yielded by the Unix
time command minus the 'time' result of an empty invocation of the
respective interpreter. As you can see, Lua beats even the Ghostscript
program with its direct, fast stack manipulation and no use of
variables.
It would be interesting to do some more comparisons with other programs,
and unfortunately, I don't have access to Quake-C that would be a more
serious competitor.

Have fun, Dolfi

time lua -e "function fib(n) if(n>2) then return fib(n-1)+fib(n-2) else
return 1 end end;print(fib(30))"
4.20-0.0

echo '/fib {dup 2 gt {dup 2 sub fib exch 1 sub fib add} {pop 1} ifelse}
def 30 fib = '> TMP.ps
time gs -dNODISPLAY -- TMP.ps
6.15-0.01

Python:
(I found no way to pass a fn definition to Python on the command line;
use a text editor
to enter the program TMP.py)
def fib(n):
  if n>2: return fib(n-1)+fib(n-2)
  else: return 1

fib(30)
<EOF>
time python TMP.py
8.53-0.04

time perl -e 'sub fib { if(@_[0]>2) { return fib(@_[0]-1)+fib(@_[0]-2);
} else { return 1; } };print fib(30);'
16.21-0.01

echo '(defun fib (n) (if (> n 2) (+ (fib (- n 1)) (fib (- n 2))) 1))
(princ (fib 30))' > TMP.el
time emacs -batch -l TMP.el
19.97-0.06

time guile -c '(write (let loop ((n 30)) (if (> n 2) (+ (loop (- n 1))
(loop (- n 2))) 1)))'
24.06-0.39

-- 
Adolf Mathias              EMail: dolfi at zkm dot de  Web: www.zkm.de
|||| / |< ||| ZKM Institute for Visual Media - Institut für Bildmedien
P.B. 6919 D-76049 Karlsruhe, Germany; fon +49 721-8100-1544, fax -1509