Skip to content

Instantly share code, notes, and snippets.

@vstakhov
Last active April 6, 2020 11:35
Show Gist options
  • Save vstakhov/1d91a5cb1e3107ce2c92dd206d03dcd7 to your computer and use it in GitHub Desktop.
Save vstakhov/1d91a5cb1e3107ce2c92dd206d03dcd7 to your computer and use it in GitHub Desktop.
function f1(t) 
  local t1 = util.get_ticks(true); 
  for i=1,1000500 do table.insert(t, i) end 
  local t2 = util.get_ticks(true)
  print(string.format("%d = %d", #t, t2 - t1))
end
function f2(t) 
  local t1 = util.get_ticks(true)
  for i=1,1000500 do t[#t+1]=i end
  local t2 = util.get_ticks(true)
  print(string.format("%d = %d", #t, t2 - t1))
end
function f3(t)
  local table = table
  local t1 = util.get_ticks(true)
  for i=1,1000500 do t[i] = i end
  local t2 = util.get_ticks(true)
  print(string.format("%d = %d", #t, t2 - t1))
end
function f4(t) 
  local t1 = util.get_ticks(true)
  for i=1,1000500 do rawset(t, i, i) end 
  local t2 = util.get_ticks(true)
  print(string.format("%d = %d", #t, t2 - t1))
end
LuaJIT 2.1.0-beta3> f1{}
1000500 = 126046156
LuaJIT 2.1.0-beta3> f2{}
1000500 = 147805824
LuaJIT 2.1.0-beta3> f3{}
1000500 = 19181378
LuaJIT 2.1.0-beta3> f4{}
1000500 = 19501276
Lua 5.3> f1{}
1000500 = 374971568
Lua 5.3> f2{}
1000500 = 277553500
Lua 5.3> f3{}
1000500 = 353550462
Lua 5.3> f4{}
1000500 = 207946138
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment