Skip to content

Instantly share code, notes, and snippets.

@sapier
Created April 30, 2014 14:37
Show Gist options
  • Save sapier/1fbe9aaa90ff5f12b14f to your computer and use it in GitHub Desktop.
Save sapier/1fbe9aaa90ff5f12b14f to your computer and use it in GitHub Desktop.
#!/usr/bin/lua
local status, module = pcall(require, 'socket')
local mytable = {}
mytable.func = function(self,a)
self.val = self.val + a
end
mytable.val = 0
local starttime1 = socket.gettime()*1000
for i=1,100000000,1 do
mytable:func(1)
end
local donetime1 = socket.gettime()*1000 - starttime1
local meta = {}
meta.__index = meta
function meta:func(a)
self.val = self.val +a
end
local table2 = {}
setmetatable(table2,meta)
table2.val = 0
local starttime2 = socket.gettime()*1000
for i=1,100000000,1 do
table2:func(1)
end
local donetime2 = socket.gettime()*1000 - starttime2
print("Time1: " .. donetime1 .. "ms Time2: " .. donetime2 .. "ms")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment