lua-users home
lua-l archive

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


On Wed, Sep 30, 2020 at 3:14 PM Egor Skriptunoff
<egor.skriptunoff@gmail.com> wrote:
> This program runs very fast:
> local t = {}
> -- t.slow = true
> for j = 1, 1e6 do t[j], t[-j] = 0, nil end
> But if you uncomment the line with the "slow" option...

Not too precise but in my case, with a simpler test:

> local s=os.time();local t={};t.a=1;for j=1,100000000 do t[-j]=nill end;print(os.time()-s)
6
> local s=os.time();local t={};for j=1,100000000 do t[-j]=nill end;print(os.time()-s)
2
> local s=os.time();local t={};t[0]=1;for j=1,100000000 do t[-j]=nill end;print(os.time()-s)
7
> local s=os.time();local t={};t[1]=1;for j=1,100000000 do t[-j]=nill end;print(os.time()-s)
3

given i and iii times are the same within the timing method error, as
are ii and iv, I will suspect that deleting an element when the hash
part is empty is very fast, as there is nothing to check, but when the
hash part is not the code needs at least to hash j and look it up,
which will dwarf the rest of the code. I mean, no rehashing involved,
just a slower emptyness test.


Francisco Olarte.