ForeverDev

Untitled

Sep 27th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.84 KB | None | 0 0
  1. --THIS:
  2.  
  3. local trials = {}
  4. local funcs = [[
  5.        
  6.     ->
  7.     for i = 1, 5 do
  8.         print("i : " .. i)
  9.     end
  10.     <-
  11.    
  12.     ->
  13.     for x = 1, 5 do
  14.         print("x : " .. x)
  15.     end
  16.     <-
  17.        
  18. ]]
  19.  
  20. for i = 1, 200 do
  21.     local now = tick()
  22.     sp(funcs).multiCall()
  23.     sp(trials).insert(tick() - now)
  24. end
  25.  
  26. print("AVERAGE RUN TIME : " .. sp(trials).average())
  27.  
  28.  
  29.  
  30.  
  31.  
  32. --INSTEAD OF THIS:
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39. local trials = {}
  40. local funcs = [[
  41.        
  42.     ->
  43.     for i = 1, 5 do
  44.         print("i : " .. i)
  45.     end
  46.     <-
  47.    
  48.     ->
  49.     for x = 1, 5 do
  50.         print("x : " .. x)
  51.     end
  52.     <-
  53.        
  54. ]]
  55.  
  56. for i = 1, 200 do
  57.     local now = tick()
  58.     funcs:gsub("%->.+<%-", function(match)
  59.         loadstring(match:gsub("[%-<*>*]+", ""))()
  60.     end)
  61.     table.insert(trials, tick() - now)
  62. end
  63.  
  64. local average = 0
  65. for _, number in ipairs(trials) do
  66.     average = average + number
  67. end
  68.  
  69. print("AVERAGE RUN TIME : " .. average / #trials)
Advertisement
Add Comment
Please, Sign In to add comment