Eccentric Developments


Raybench - Lua (Programming Languages Comparison pt.3)

Going for the low hanging fruit...

For this and the following two or three posts, I'll be taking on programming languages that I already know; this time, Lua.

Lua is a dynamic language with an easy syntax, similar to pseudocode; functions are first class citizens and it is very easy to embed into larger programs.

One big point in favor is that its more common interpreters: luajit and the regular lua interpreter, are very fast when loading, and have a very small footprint. Also, both are available in a wide range of platforms.

Results

Two interpreters where used to measure Lua performance: lua 5.2.3 and luajit 2.0.2

Loading time

Lua being an interpreted language has no compilation phase, compared to languages like C or Haskell. The following are the timings for how long the interpreter takes to load the code and parse it. For this, I simply commented out the last line to avoid triggering the rendering.

--main()
$ time lua luarb.lua 

real    0m0.092s
user    0m0.000s
sys     0m0.000s
$ time luajit luarb.lua 

real    0m0.063s
user    0m0.000s
sys     0m0.000s

Loading times are blazing fast.

Running time

$ time lua luarb.lua 

real    611m38.925s
user    605m54.136s
sys     0m37.716s
$time luajit luarb.lua 

real    225m58.621s
user    224m2.140s
sys     0m14.044s

As can be seen, luajit is almost 3x as fast as the regular lua interpreter, but both lag way behind the 2 minutes mark from C.

Code metrics

Line count: 283 code, 103 blanks, 386 total. File size: 6685 bytes

General Thoughts

Lua has a very simple syntax that reminds me of BASIC, it's easy to read, variable types are dynamic and functions can be passed around. I have used it as a scripting language in some other projects with no problem, the interpreter is very easy to embed.

Too bad it's very slow while running, although it's not meant to be used for high performance computing, it is a bit of a let down. Code is just a bit more compact than C, but has an abysmal performance.

Follow

You can follow the development of this project on GitHub: https://github.com/niofis/raybench