Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Performance numbers on "if [" vs. "[" alone vs. "if [[" vs. "[[" alone



% zsh-5.2 -f

===> if [ "$a" = "1" ]

typeset -F SECONDS; SECONDS=0; repeat 100000; do if [ "$a" = "1" ];
then echo yes; fi; done; echo $SECONDS
1.0209490000


===> [ "$a" = "1" ]

typeset -F SECONDS; SECONDS=0; repeat 100000; do [ "$a" = "1" ] &&
echo yes; done; echo $SECONDS
0.6701160000


===> if [[ "$a" = "1" ]]

typeset -F SECONDS; SECONDS=0; repeat 100000; do if [[ "$a" = "1" ]];
then echo yes; fi; done; echo $SECONDS
0.5131310000


===> [[ "$a" = "1" ]]

typeset -F SECONDS; SECONDS=0; repeat 100000; do [[ "$a" = "1" ]] &&
echo yes; done; echo $SECONDS
0.0925930000


Best regards,
Sebastian Gniazdowski



Messages sorted by: Reverse Date, Date, Thread, Author