[Lua性能] 小试验一例
local s1 = os.clock() local list1 = {} for i = 1, 100000 do list1[#list1 + 1] = 1 end local e1 = os.clock() print("runtime1 = " .. (e1 - s1)) local s2 = os.clock() local list2 = {} local index = 1 for i = 1, 100000 do list2[index] = 1 index = index + 1 end local e2 = os.clock() print("runtime2 = " .. (e2 - s2))
output:
runtime1 = 0.008
runtime2 = 0.003
[Finished in 0.1s]
By wmalloc