[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Calculating estimate for size of a lua table
- From: Lars Müller <appgurulars@...>
- Date: Sat, 13 Aug 2022 21:34:47 +0200
Thanks for the correction.
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")
which consistently printed a size of
about 39 bytes for each hash entry on both PUC Lua 5.4 and LuaJIT
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.
On 13.08.22 19:32, Xmilia Hermit wrote:
Lars
Müller:
I would assume the following:
For the list part: 8 bytes for each entry.
For the hash part: 8 bytes (key) + 8 bytes (value) for each
entry.
It is more like 16 bytes for the list part as PUC Lua uses tagged
values (8 byte value + 1 byte tag) which is rounded up to 16.
For the hast part it is likely 24. (2 * 8 byte value (for value +
key) + 2 * 1 byte tag (for value + key) + 4 byte link to next
element when multiple have the same hash rounded up to 24).
And the empty table has likley 64 byte of a constant cost.
So in total something like 64 + 16 * array_size + 24 * hash_size
where the sizes are power of two's.
Regards,
Xmilia