help-bash
[Top][All Lists]
Advanced

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

[Help-bash] Is there any performance difference between [[ $# -eq 0 ]] a


From: Peng Yu
Subject: [Help-bash] Is there any performance difference between [[ $# -eq 0 ]] and (($#==0))
Date: Sun, 30 Jul 2017 07:23:09 -0500

Hi,

I don't see a robust difference in runtime between [[ $# -eq 0 ]] and
(($#==0)). Are they the same in performance?

$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

declare -i i
declare -i n
n=500000

i=0
time while ((i<n))
do
    [[ $# -eq 0 ]]
    ((++i))
done

i=0
time while ((i<n))
do
    (($#==0))
    ((++i))
done

~$ ./main.sh

real    0m4.598s
user    0m4.478s
sys    0m0.006s

real    0m4.858s
user    0m4.563s
sys    0m0.013s
~$ ./main.sh

real    0m4.153s
user    0m4.137s
sys    0m0.004s

real    0m4.086s
user    0m4.056s
sys    0m0.004s

-- 
Regards,
Peng



reply via email to

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