Created
September 17, 2014 14:29
-
-
Save YellowAfterlife/81db98272cfdbb0f61d1 to your computer and use it in GitHub Desktop.
Comparisons for what is "var2 = (var1 = value)" in other languages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function set_field(t, f, v) | |
t[f] = v | |
return v | |
end | |
local n = 10000000 | |
local t = { } | |
local q | |
local p | |
-- Direct: | |
q = os.clock() | |
for i = 1, n do | |
t.one = i | |
t.two = t.one | |
end | |
print(os.clock() - q) | |
-- set_field: | |
q = os.clock() | |
for i = 1, n do | |
t.two = set_field(t, 'one', i) | |
end | |
print(os.clock() - q) | |
-- inline function: | |
q = os.clock() | |
for i = 1, n do | |
t.two = (function() p = i; return p end)() | |
end | |
print(os.clock() - q) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment