help-bash
[Top][All Lists]
Advanced

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

[Help-bash] slow in function creation


From: Peng Yu
Subject: [Help-bash] slow in function creation
Date: Mon, 3 Dec 2018 22:26:27 -0600

Hi,

I see that function creation can be much slower than typeset -F when
there are many functions. Why function creation can be so slow? Is
there a way to improve its runtime?

I see that the typeset -F slows down ~10x from 100000 to 1000000. Is
100000 approximately the bucket size of the hash storing the
functions?

$ ./main.sh
==> 1 <==
0.008
0.000
1.254
==> 10 <==
0.009
0.000
1.291
==> 1000 <==
0.013
0.007
1.280
==> 10000 <==
0.022
0.065
1.296
==> 100000 <==
0.110
1.706
1.767
==> 1000000 <==
1.015
218.159
10.999
$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

tmpfile=$(mktemp -u)
TIMEFORMAT=%R
for n in 1 10 1000 10000 100000 1000000
do
    echo "==> $n <=="
    time awk -v n="$n" -e 'BEGIN { for(i=1;i<n;++i) printf("function
f%d { :; }\n", i) }' > "$tmpfile"
    time source "$tmpfile"
    time for ((i=0;i<100000;++i))
    do
        typeset -F f0
    done > /dev/null
done

-- 
Regards,
Peng



reply via email to

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