Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2013
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.63 KB | None | 0 0
  1. require "socket"
  2. l = {}
  3. for i=1,3000 do
  4.   l[i - 1] = function() math.random(1) end -- populate
  5. end
  6.  
  7. function test()
  8.   local l = l
  9.   for i,d in pairs(l) do
  10.     d()
  11.   end
  12. end
  13.  
  14. function test_global()
  15.   for i,d in pairs(l) do
  16.     d()
  17.   end
  18. end
  19.  
  20. print "testing local"
  21. local starttime = socket.gettime()
  22. for i=1,6000 do
  23.   test()
  24. end
  25. local endtime = socket.gettime()
  26. print("Took " .. ((endtime - starttime) * 1000) .. " milliseconds")
  27.  
  28. print "testing global"
  29. starttime = socket.gettime()
  30. for i=1,6000 do
  31.   test_global()
  32. end
  33. endtime = socket.gettime()
  34. print("Took " .. ((endtime - starttime) * 1000) .. " milliseconds")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement