Speed of hash tables compared to lua
Domingo
mingodad at gmail.com
Sun Sep 13 10:06:56 UTC 2020
On Sunday, 13 September 2020 at 09:50:27 UTC, Domingo wrote:
> Hello !
> Doing some tests I found that D hash tables are a lot slower
> than Lua tables see bellow, D is using 2 times more memory and
> 5 times more time compared to Lua, when comparing with Luajit
> it's unbelievable worse.
>
> I would expect a compiled language like D to use less resources
> than a scripting language, anyone have experienced something
> similar ?
>
> Does the community know this ?
>
> I hope this simple test would help to test and improve the
> situation !
>
After writing the previous message I realized the test was not
exactly fair, Lua was probably using the array functionality of
it's table so I changed it a bit and now Lua uses as much memory
as D but still is faster by a good margin (~4).
=====
local dsize = 6000008;
local d = {};
for i=dsize, 1, -1
do
if ((i % 2) == 0) then d[i] = 0.0000000123;
else d[i] = 12345.0000000001; end
end
local sum = 0.0;
for i=dsize, 1, -1
do
sum = sum + d[i];
end
print(string.format("count: %d, sum: %35.15f\n", #d, sum));
=====
=====
/usr/bin/time lua sum-test-rev.lua
count: 6000008, sum: 37035049380.000160217285156
0.63user 0.11system 0:00.74elapsed 100%CPU (0avgtext+0avgdata
264500maxresident)k
0inputs+0outputs (0major+98435minor)pagefaults 0swaps
=====
=====
/usr/bin/time luajit sum-test-rev.lua
count: 6000008, sum: 37035049380.000160217285156
0.48user 0.04system 0:00.52elapsed 100%CPU (0avgtext+0avgdata
117240maxresident)k
0inputs+0outputs (0major+41086minor)pagefaults 0swaps
=====
More information about the Digitalmars-d
mailing list