Skip to content

Instantly share code, notes, and snippets.

@mraleph
Created January 5, 2016 12:34
Show Gist options
  • Save mraleph/7a75daee13ad783d8f78 to your computer and use it in GitHub Desktop.
Save mraleph/7a75daee13ad783d8f78 to your computer and use it in GitHub Desktop.
$ src/luajit test1.lua                                            
test3/lua 0.000812
test2/lua 0.047739
$ src/luajit test2.lua
test2/lua 0.050938
test3/lua 0.000856
require "vector3"
collectgarbage()
test3()
collectgarbage()
test2()
require "vector3"
collectgarbage()
test2()
collectgarbage()
test3()
local Vector3 = { __typename = 'Vector3' }
do
local setmetatable = setmetatable
local I = { __typename='Vector3' }
Vector3.__call = function(t, x, y, z)
return setmetatable({x or 0, y or 0, z or 0}, I)
end
setmetatable(Vector3, Vector3)
end
function test2()
local start = os.clock()
for i = 1,200000 do
local up = Vector3(0,1,0)
tostring(up)
end
print("test2/lua " .. (os.clock() - start));
end
function test3()
local start = os.clock()
for i = 1, 2000000 do
Vector3(i, i, i)
end
print("test3/lua " .. (os.clock() - start));
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment