I recently wrote a
post about how to make a raytracer. The raytracer code was then written in JavaScript. I wondered how Lua would cope with this task, namely
LuaJIT 2.0 . Below are the results of the comparison.
')
Chrome 9.0 Beta, Opera 11.01, Firefox 4.0 Beta 9, Explorer 9 Beta and LuaJIT 2.0 Beta 5 took part. All five participants rendered the same scene on a 1000x1000 screen with three beams per pixel. Here is the scene:
The results are as follows (RPS means “number of rays per second”):
Chrome | 20,400 RPS |
Opera | 15.700 RPS |
Firefox | 9,300 RPS |
Explorer | 9,000 RPS |
LuaJIT | 5,000 RPS |
Unexpected result: LuaJIT was the slowest, and with a margin from the other participants.
As noted by
FreeLancer , you can change the settings of the garbage collector in Lua. If you add a collectgarbage line ('setpause', 2000) to the beginning of the code, then the garbage collector will rarely interrupt the raytracer and the speed will increase to 25,000 RPS, but the peak memory consumption will grow to 1.5 gigabytes. Chrome “ate” only 150 MB when it showed a result of 20,400 RPS.
Here you can download the code for the examples:
JavaScript and
LuaJIT . The JS and Lua code is identical, except for minor syntactic differences. To run the Lua example on yourself, you need to make the luajit.exe file for yourself (take it from the LuaJIT website or compile it from source) and run it on the command line
luajit main.lua