lua-users home
lua-l archive

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


David Jeske <jeske@chat.net> wrote:
> On Tue, Jul 18, 2000 at 05:53:22AM -0300, Peter Wang wrote:
> > If you need more speed, I'd suggest you look around at a few Forth
> > or Lisp/Scheme interpreters (e.g. QScheme). 
> 
> When I originally found Lua, I tested some common operations (loops,
> math, etc) against a few Scheme interpreters and found Lua much faster
> (although I didn't test QScheme).

Lua *is* faster than most Lisp and Scheme interpreters I've tried.
I just got a little biased because QScheme is so bloody fast :-)

and Adolf Mathias <dolfi@zkm.de> wrote:
> 
> All Schemes/Lisps I know as well as Perl (including Emacs-Lisp which is
> reputedly very fast) are behind by a factor of at least 3 to 4. 

I felt compelled to test out a few of my arguments from yesterday,
so I ran a couple of simple tests on my Pentium 133, using the Unix
`time' command (user + system).  Times are given in seconds.

		wloop	      fib
		-----	    -------
      QScheme	 2.05	       7.53
      Lua	 4.74	      20.46
      Python	16.56	    1:13.17

Please note that QScheme uses a few GCC extensions (meaning it is
not ANSI C), which may explain the speed difference.  I don't
currently have a Forth on my machine to test with, and I didn't feel
like writing Perl code (it would probably be somewhere between Lua
and Python).

Here are source listings (scheme code came with QScheme, direct Lua
and Python translations by me).

wloop.scm:

    (define (loop i l) (while (< i l) (set! i (+ i 1))))
    (loop 0 3000000)

wloop.lua:

    function loop (i, l) while i < l do i = i + 1 end end
    loop (0, 3000000)

wloop.py:

    def loop (i, l):
        while i < l: i = i + 1
    loop (0, 3000000)

fib.scm:

    (define (fib n) (if (<= n 2) 1 (+ (fib (- n 1)) (fib (- n 2)))))
    (fib 30)
    (fib 30)
    (fib 30)

fib.lua:

    function fib (n)
        if n <= 2 then
            return 1
        else
            return fib (n - 1) + fib (n - 2)
        end
    end

    fib (30)
    fib (30)
    fib (30)

fib.py:

    def fib (n):
        if n <= 2:
            return 1
        else:
            return fib (n - 1) + fib (n - 2)

    fib (30)
    fib (30)
    fib (30)


That's enough crap from me.

-- 
tjaden@psynet.net - http://www.psynet.net/tjaden/
"Money is the root of all money." -- the moving finger