Lua Performance Tests

Posted on March 08, 2011 in General

Just for some experimentation, I did some performance tests on a few operations in Lua. To time them I used the command, time lua test.lua, and took the "real" time. The test file was just a loop, which looped 20 million times:

for i = 1, 20000000 do --[[ code here ]] end

Alright, here's the results.

Description Seconds Loop Code Variable/Function Definition
Empty function call 1.249 f() function f() end
Return function call 1.688 f() x = 0
function f() return x end
Assignment 0.76 x = 0  
Table property assignment 1.097 x.y = 'f' x = { y = 'f' }
Table creation 10.495 x = { y = 'f' }  
Table sorting 19.742 table.sort(x) x = {'f', 'k', 'a', 'b', 'e'}
Simple addition 1.295 x = x + 1 x = 0
Nothing 0.144 do end  

I think we can conclude that Lua is pretty fast.


Tagged in Lua, programming
blog comments powered by Disqus