lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Lars Müller:

I did some benchmarking using the following code:
for i = 1, 10 do collectgarbage"collect" end; c = collectgarbage"count"; t = {}; for i = 1, 1e7 do t[i+.5] = i end; d = collectgarbage"count"; print((d - c) * 1e3 / 1e7, "bytes per entry")
You should look out since as you noted the length of the array and hash part are power of two's, so in the worst case this can give double the cost when using random lengths. So using power of two's instead of 1e7 would be better.
For the list part I simply used "t[i] = i" in the above code. Surprisingly the list part only takes 13 bytes per entry on LuaJIT (!) vs 26 bytes per entry on Lua 5.1 and Lua 5.4.
I would argue that this is not surprising as LuaJIT uses NaN boxing which allows to store all values in 8 bytes instead of the 16 used by PUC Lua which is reflected in your benchmarking.

Regards,
Xmilia