Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- output:
- ------------------------
- Control: 0.0090000000000146
- Test A: 0.02349999999999
- Test B: 0.1049
- Test C: 0.1067
- ------------------------
- conclusion: localize deeply nested variables before loop
- --]]
- local clock = os.clock
- local this = { is = { a = { deep = { tbl = { dude = true } } } } }
- -- 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 is_a_dude = this.is.a.deep.tbl.dude
- local before = clock()
- for i=1,1000000 do
- if (is_a_dude == true) then
- end
- 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
- if (this.is.a.deep.tbl.dude == true) then
- end
- end
- sum = sum + (clock()-before)
- itr = itr + 1
- until (itr == 10)
- local test_b = sum/itr
- -- TEST C
- sum = 0
- itr = 0
- repeat
- local before = clock()
- for i=1,1000000 do
- local is_a_dude = this.is.a.deep.tbl.dude
- if (is_a_dude == true) then
- end
- end
- sum = sum + (clock()-before)
- itr = itr + 1
- until (itr == 10)
- local test_c = sum/itr
- print ("Control: "..test_control)
- print ("Test A: "..test_a)
- print ("Test B: "..test_b)
- print ("Test C: "..test_c)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement