help-bash
[Top][All Lists]
Advanced

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

[Help-bash] Is [[ $x = $y ]] faster than [ "$x" = "$y" ]?


From: Peng Yu
Subject: [Help-bash] Is [[ $x = $y ]] faster than [ "$x" = "$y" ]?
Date: Sat, 29 Jul 2017 16:19:33 -0500

Hi,

I have the following test case. Can I make the conclusion that [[ $x =
$y ]] is faster than [ "$x" = "$y" ] in general? Thanks.

$  ./main.sh

real    0m3.769s
user    0m3.739s
sys    0m0.005s

real    0m7.890s
user    0m7.579s
sys    0m0.010s


$ ./main.sh

real    0m3.769s
user    0m3.739s
sys    0m0.005s

real    0m7.890s
user    0m7.579s
sys    0m0.010s
$ 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
    [[ $x = $y ]]
    ((++i))
done

i=0
time while ((i<n))
do
    [ "$x" = "$y" ]
    ((++i))
done

-- 
Regards,
Peng



reply via email to

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