39 points · by critic · 17y ago · 72 comments
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.
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.
SBCL is faster still, averaging about half the speed of GCC and about the same as Java.
Short paper, but very interesting.
The LPEG paper (http://www.inf.puc-rio.br/~roberto/docs/peg.pdf) is great, too.
If you use Lisp’s static annotation
system, your code becomes uglier than
Java, and much less safe (I don’t think
Lisp does static checking of parameter
types, it just goes ahead and passes you
an object and lets you think it’s an integer).
Additionally, Lua only has "one data structure type" - that's also "higher-level" than what you have to do in Lisp, deciding among singly-linked lists, arrays, hash tables, binary trees, lexical trees, etc.So while SBCL has its place, there's something about Lua you have to admire, don't you think?
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... and using it http://svn.apache.org/repos/asf/httpd/httpd/trunk/modules/lu... ).
To get started with Lua, I'd recommend PIL: http://www.lua.org/pil/
For example, Lua's use of two dashes for line comments, and --[[ and --]] for block quotes. That lets you remove the first --[[ in a block quote without causing the program to break, because the "closing" block quote is commented out at that point (because --]] is a comment at that point). But really, that's so different from other languages that it seems like a liability rather than an asset. That's what I meant by "not necessarily beautiful". It is definitely beautiful in certain other aspects, though.
Also, if I were writing a scripting language, I'd love for it to be "like a prostitute". Even if nobody respected it, everyone would be using it.
Similarities: Block/lambda support and syntax, optional parentheses, control statements as block, prefix, or postfix.
OTOH, "how come Lua is not as widespread as say, Python ? I'd say the answer is this: there is no real standard library, and as opposed to Python, Lua doesn't come with batteries included." -- http://www.ivy.fr/blog/index.php/2008/03/17/83-kahlua-lua-on...
On the other hand, interfacing to C is the nicest of anything I have done, by a long shot, so the lack of batteries isn't that painful in practice. It fills a different niche than python or ruby, in its, it shines.
Thus, I feel a Lua - to - Ruby/Python comparison is sort of erroneous. Use Lua when you already have all your tools. Use Ruby/Python when you don't have any tools, and you want cool whizbang higher-level stuff.
Honestly the benchmark is wholly unsurprising to me; Lua is a much more minimal language. If you need another language to lump Lua with, lump it with Javascript sooner than you would Ruby or Python.
In short, Lua's philosophy is to keep the core language as small as possible, but to include features that make it easy to add major language features as necessary. Adding an object system to the language is trivial, for example. (It doesn't have hygienic macros, though there are some side projects that attempt to add them. No experience with them, though...I'd just use Scheme.) Lua feels to me like a minimalistic, more internally consistent Python.
Results look almost the same ;-)
http://shootout.alioth.debian.org/u32/benchmark.php?test=all...
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.
Better yet, LuaJIT is a drop-in replacement. There's no reason not to use it, as far as I know.
LuaJIT 1.1.4 Copyright (C) 2005-2008 Mike Pall
ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-linux]
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.
I think Ruby in general is less amenable to analysis/compilation than Lua is, so even a JITed Ruby might not do as well as Lua.
http://shootout.alioth.debian.org/gp4/benchmark.php?test=all...
so, i'd take it with a huge slab of salt.
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.