Advertisement
snake5

silly optimizers

Jun 18th, 2013
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.95 KB | None | 0 0
  1.  
  2.  
  3. local unit, weapon
  4.  
  5.  
  6. function doSomething()
  7.     _G['lol'] = 1
  8. end
  9.  
  10.  
  11. ArmedUnits = {}
  12. Units = {}
  13. Weapons = {}
  14. for i=1, 90000,1 do
  15.     ArmedUnits[i] = { unit = 5, weapon = 5 }
  16.     Units[i] = 5
  17.     Weapons[i] = 5
  18. end
  19.  
  20.  
  21. t1 = os.clock()
  22.  
  23. for i=1, 90000,1 do
  24.     if Units[i] == Weapons[i] then doSomething() end
  25. end
  26.  
  27. t2 = os.clock()
  28.  
  29. for i=1, 90000,1 do
  30.     unit = ArmedUnits[i].unit
  31.     weapon=ArmedUnits[i].weapon
  32.     if unit == weapon then doSomething() end
  33. end
  34.  
  35. t3 = os.clock()
  36.  
  37.  
  38. print( "Method 1: " .. t2-t1 )
  39. print( "Method 2: " .. t3-t2 )
  40.  
  41.  
  42.  
  43. -- Output:
  44.  
  45. C:\Misc\binlua>lua52 test.lua
  46. Method 1: 0.016
  47. Method 2: 0.019
  48.  
  49. C:\Misc\binlua>lua52 test.lua
  50. Method 1: 0.016
  51. Method 2: 0.019
  52.  
  53. C:\Misc\binlua>lua52 test.lua
  54. Method 1: 0.015
  55. Method 2: 0.02
  56.  
  57. C:\Misc\binlua>lua52 test.lua
  58. Method 1: 0.016
  59. Method 2: 0.019
  60.  
  61. C:\Misc\binlua>lua52 test.lua
  62. Method 1: 0.016
  63. Method 2: 0.02
  64.  
  65. C:\Misc\binlua>lua52 test.lua
  66. Method 1: 0.015
  67. Method 2: 0.02
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement