bug-gawk
[Top][All Lists]
Advanced

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

Re: gawk array index: string vs integer


From: J Naman
Subject: Re: gawk array index: string vs integer
Date: Tue, 12 Dec 2023 13:34:23 -0500

I ran Ed's benchmark functions and observed another relationship. I
originally thought the issue was tracking the 'tos' without actually
deleting the top of the stack (which I normally do not do because there is
some stack 'history' for debugging, etc.).
Removing the delete in pop(), no other changes, what I saw was:
# ==> tst_numeric.awk <==
function pop(x)    { delete x[x[0]--] }
# ==> tst_numeric2.awk <==
function pop(x)    { x[0]-- }
Real time is 8% faster without the delete and double x[] index lookup

# ==> tst_string.awk <==
function pop(x)    { delete x[x["tos"]--] }
# ==> tst_string2.awk <==
function pop(x)    { x["tos"]-- }
Real time is 1/2, 50% as fast, without the delete and double x[] index
lookup

IF not deleting the string 'tos', there is no double lookup using the
string index. That obviously keeps memory allocated to the largest stack
depth, which might be very bad in some recursive functions, i.e., memory
overflow.
Still, as Ed pointed out (I never knew!), array index string vs integer can
have a very significant performance difference.
Just saying ... john


reply via email to

[Prev in Thread] Current Thread [Next in Thread]