[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
performance bug of [[ $x ]]
From: |
Peng Yu |
Subject: |
performance bug of [[ $x ]] |
Date: |
Sat, 7 Mar 2020 16:48:46 -0600 |
[[ $x ]] just tests whether the variable $x is of length 0 or not. So
its performance should not depend on how long the variable is.
But the following test case shows that the run time does depend on the
length of the variable.
Should it be considered as a performance bug of bash?
$ x=$(printf '%.sx' {1..1000000})
$ time [[ $x ]]
real 0m0.004s
user 0m0.003s
sys 0m0.000s
$ x=$(printf '%.sx' {1..10000000})
$ time [[ $x ]]
real 0m0.043s
user 0m0.039s
sys 0m0.004s
--
Regards,
Peng
- performance bug of [[ $x ]],
Peng Yu <=