
Lua vs Ruby benchmarks (similarly "high-level" languages, insanely different performance) - critic
http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=luajit&lang2=ruby
======
henning
LuaJIT is not the standard mainline Lua interpreter that most people think of
as "Lua the language". It's still a fairly young, experimental project and you
wouldn't want to write production code in it. However, the standard Lua
distribution is still much faster than Ruby.

But even though both are dynamic interpreted languages, it's still apples to
oranges - they have very different design goals.

Still, I think it's a copout to say performance doesn't matter in any general-
purpose language the way the core Ruby team seems to. Micro-optimization is a
waste of time, but efficiency and intelligent implementation choices are
necessary.

~~~
silentbicycle
It also only runs on i386.

In practice (not micro-benchmarks), I've found LuaJIT to be at least twice as
fast as the standard version, and in some cases three or better.

------
Zak
Without some discussion of why Lua is faster, this isn't very interesting. Lua
is known for being small and fast, so this benchmark shouldn't be news to most
people here.

SBCL is faster still, averaging about half the speed of GCC and about the same
as Java.

~~~
silentbicycle
The first place to look is probably "The Implementation of Lua 5.0"
(<http://www.tecgraf.puc-rio.br/~lhf/ftp/doc/sblp2005.pdf>).

Short paper, but very interesting.

The LPEG paper (<http://www.inf.puc-rio.br/~roberto/docs/peg.pdf>) is great,
too.

~~~
LogicHoleFlaw
The "History of Lua" paper written a few years ago for a presentation at HOPL
is also great reading and gives good insight into why Lua is the way it is.

<http://www.tecgraf.puc-rio.br/~lhf/ftp/doc/hopl.pdf>

------
nod
I don't know Lua, but this is the first time I've heard Lua and Ruby equated
in terms of expressibility/flexibility (i.e. "high-level"?). Is that a
particularly relevant comparison?

~~~
brianm
Having done a lot of both, Lua feels more pythonic than rubyish in many small
ways. Objects are just syntactic sugar where self is the first arg (though
unlike python, lua _has_ the syntactic sugar to make it prettier to look at),
etc. Interestingly, typical OO Lua is prototype based, not class based -- in
that way it is more javascriptish.

Most lua codebases I have seen tend to be written in what I call an
"imperative functional" style, where the language isn't purely functional, but
functions are the most common means of abstraction.

It has proper anonymous functions, lexical scoping, etc so you can write very
rubyish code (such as moonunit
[http://svn.apache.org/repos/asf/httpd/httpd/trunk/modules/lu...](http://svn.apache.org/repos/asf/httpd/httpd/trunk/modules/lua/test/moonunit.lua)
and using it
[http://svn.apache.org/repos/asf/httpd/httpd/trunk/modules/lu...](http://svn.apache.org/repos/asf/httpd/httpd/trunk/modules/lua/test/test.lua)
).

~~~
Xichekolas
A unit testing framework in 37 lines of code, not too shabby.

~~~
brianm
with color coded output ;-)

------
brianm
Personally, I would hav just done Lua vs Ruby instead of LuaJIT vs Ruby.

Results look almost the same ;-)

[http://shootout.alioth.debian.org/u32/benchmark.php?test=all...](http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=lua&lang2=ruby)

Lua is generally the fastest scripty language, ruby is generally the slowest.
Ruby is much more general purpose though -- Lua is very optimized for
embedding.

~~~
palish
LuaJIT makes the Lua _mandelbrot_ program run 95 times faster than Ruby's,
whereas the stock Lua interpreter is only 17 times faster.

Better yet, LuaJIT is a drop-in replacement. There's no reason not to use it,
as far as I know.

~~~
brianm
I love the "only 17 times faster" bit ;-)

~~~
lliiffee
Try comparing ruby to c++!

------
FraaJad
mod_lua will be in the next stable apache release. <http://lua-
users.org/lists/lua-l/2008-12/msg00119.html>

------
joe_the_user
Who would care to implement Ruby in Lua?

~~~
silentbicycle
While it would be an interesting project, the Ruby wouldn't necessarily be
faster for it. I don't know Ruby well enough to say, but there are probably
aspects in the language design itself that make it slower (as a trade-off for
expressiveness). Lua is very fast, but that comes from aggressively
simplifying the core of the language. Most things are ultimately built on only
a few central constructs, and they have been very throughly optimized.

------
Locke
Which version of Ruby? 1.8 or 1.9? With my own projects Ruby 1.9 performs much
better. Lua is well known for being small and fast, so I doubt Ruby 1.9 would
beat it... Nevertheless, it'd be a lot more interesting comparison that Lua vs
Ruby ???.

~~~
jmatt
I had to reverse the dropdown values to get both the versions..

LuaJIT 1.1.4 Copyright (C) 2005-2008 Mike Pall

ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-linux]

------
rufius
Looks like perf comparison between both Python and Python 3 against Lua isn't
far off from Ruby and Lua... not really surprised. Like everyone else said,
Lua is smaller and leaner.

------
compay
This year my new year's resolution was to learn Lua. I think with some
developer attention it has the potential to become a "better PHP" for web
development because it beats PHP in performance, simplicty and elegance.

Although I doubt it's going to ever replace PHP I think it's poised to make
some inroads now that the next version of Apache will include mod_lua out of
the box.

<http://news.ycombinator.com/item?id=452396>

------
jcapote
Of course; Get a native JIT'ed version of ruby going, then you can make a fair
comparison.

~~~
NyxWulf
Unlike say...JRuby?

~~~
jim-greer
JRuby is not a JIT for Ruby, and it doesn't compile Ruby to Java bytecode.
It's a Ruby interpreter, written in Java.

~~~
cschneid
Recent work in JRuby does exactly that. It'll JIT your code, and you an even
pre-compile if you want.

(AFAIK, just seen references to all this).

~~~
jim-greer
Cool! Looks like it's been around for over a year:

<http://wiki.jruby.org/wiki/JRuby_Compiler>

------
Adkron
Are both sets of code optimized?

------
zcrar70
I wonder how it would compare with Ruby 1.9 (released today)?

~~~
Zak
You don't have to wonder - all the code is downloadable. You can run the
benchmark on Ruby 1.9 yourself.

~~~
zcrar70
That's true, but I'll live with wondering a little longer. In the meantime, it
seems that Lua is still quite a bit faster than ruby 1.9.0, even though ruby
1.9.0 is approaching Python 2 territory (tested 7 months ago):

[http://shootout.alioth.debian.org/gp4/benchmark.php?test=all...](http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=yarv&lang2=lua)

------
kingkongrevenge
LuaJIT is x86 only, so it's not quite apples to apples.

~~~
lbrandy
I don't know what's going on with Ruby's 'fasta' implementation, but I'm
pretty sure it's not x86 assumptions that cause Ruby to use 231x the RAM.

~~~
kingkongrevenge
I'm sure, but luajit wins handily over all the scripting interpreters. I'm not
much concerned with ruby in particular. I'm suspicious that luajit is
constrained in features. I doubt you can dynamically load in object code for
modules, for example. This makes it not quite a straightforward comparison to
the other interpreters.

~~~
LogicHoleFlaw
Actually, this is incorrect. LuaJIT is explicitly compatible with the standard
Lua ABI for modules.

<http://luajit.org/luajit_features.html>

Since it is able to use certain non-ANSI C features on the various platforms
it supports it can do other neat things like enable coroutine calls across
Lua/C stack boundaries.

