Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- output:
- ----------------------------
- Control: 0.0091000000000008
- Test A: 0.03180000000001
- Test B: 0.031799999999998
- ----------------------------
- conclusion: Difference is negligible if you localize outside loop
- Note, if you remove local a,b,c from Test A here are the results:
- -----------------------------------
- Control: 0.0089999999999918
- Test A: 0.1145
- Test B: 0.033200000000011
- -----------------------------------
- conclusion: localize globals
- --]]
- local clock = os.clock
- -- Control group: empty for loop for comparison to Test A and B
- local sum = 0
- local itr = 0
- repeat
- local before = clock()
- for i=1,1000000 do
- end
- sum = sum + (clock()-before)
- itr = itr + 1
- until (itr == 10)
- local test_control = sum/itr -- The average time
- -- TEST A
- sum = 0
- itr = 0
- repeat
- local a,b,c
- local before = clock()
- for i=1,1000000 do
- a = 2
- b = 2
- c = a + b
- end
- sum = sum + (clock()-before)
- itr = itr + 1
- until (itr == 10)
- local test_a = sum/itr
- -- TEST B
- sum = 0
- itr = 0
- repeat
- local before = clock()
- for i=1,1000000 do
- local a = 2
- local b = 2
- local c = a + b
- end
- sum = sum + (clock()-before)
- itr = itr + 1
- until (itr == 10)
- local test_b = sum/itr
- print ("Control: "..test_control)
- print ("Test A: "..test_a)
- print ("Test B: "..test_b)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement