Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15998

performance bug of [[ $x ]]

From Peng Yu <pengyu.ut@gmail.com>
Newsgroups gnu.bash.bug
Subject performance bug of [[ $x ]]
Date 2020-03-07 16:48 -0600
Message-ID <mailman.2266.1583621332.2412.bug-bash@gnu.org> (permalink)
References <CABrM6w=ignEwgynRTYYbBLUNs=KVhE8WCf9h=kkgHj00QNoqmw@mail.gmail.com>

Show all headers | View raw


[[ $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

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

performance bug of [[ $x ]] Peng Yu <pengyu.ut@gmail.com> - 2020-03-07 16:48 -0600

csiph-web