3 ms·
_G[42] is probably still hitting the hash unless you populated it with 1 to 41.
by tedunangst 8y ago
_G[42] is probably still hitting the hash unless you populated it with 1 to 41.
- wahern 8y agoI was getting some spurious runs where the array access was slower, but didn't think it was worthwhile to mention in the post. Immediately after posting my curiosity got the better of me. After filling in _G[1,2048] the times were consistently the same. The code I was playing with: local n = 16777216 local _G = _G for i=1,2048 do _G[i] = i end do local start = os.clock() for i=1,n do local f = _G["print"] end print(os.clock() - start) end do local start = os.clock() for i=1,n do local f = _G[42] end print(os.clock() - start) end