lua-users home
lua-l archive

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


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
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))"

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

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

time python

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

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

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

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