testing test function

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

testing test function

Karl Godt
Puppy's code usually uses square brackets for doing tests .

I was thinking of aliasing test to t
because on german keyboard layout it needs to press AltGr to print curly and square brackets,
en_US keyboards are quite better in this regard .

So I made a small test_test.sh script :

#eval "alias t=test"
alias t=test

#ln -s busybox /bin/test
#rm /tmp/non_existent

for nr in `seq 1 1 10000`
case $1 in
    test|1)             test -f /tmp/non_existent && echo /tmp/non_existent exists;;
       t|2)                t -f /tmp/non_existent && echo /tmp/non_existent exists;;
 bintest|3)        /bin/test -f /tmp/non_existent && echo /tmp/non_existent exists;;
   brack|4)              [ -f /tmp/non_existent ] && echo /tmp/non_existent exists;;
binbrack|5)         /bin/[ -f /tmp/non_existent ] && echo /tmp/non_existent exists;;
doublebrack|6)         [[ -f /tmp/non_existent ]] && echo /tmp/non_existent exists;;
bindoublebrack|7) /bin/[[ -f /tmp/non_existent ]] && echo /tmp/non_existent exists;;
*) echo "Unhandled parameter '$1'";break;;

TIMEs are :

bash-3.2# time /root/test_test.sh 1

real	0m0.251s
user	0m0.157s
sys	0m0.101s
bash-3.2# time /root/test_test.sh 2

real	0m0.261s
user	0m0.184s
sys	0m0.084s
bash-3.2# time /root/test_test.sh 3

real	0m10.993s
user	0m0.280s
sys	0m2.597s
bash-3.2# time /root/test_test.sh 4

real	0m0.312s
user	0m0.199s
sys	0m0.123s
bash-3.2# time /root/test_test.sh 5

real	0m10.866s
user	0m0.321s
sys	0m2.637s
bash-3.2# time /root/test_test.sh 6

real	0m0.332s
user	0m0.232s
sys	0m0.106s
bash-3.2# time /root/test_test.sh 7

real	0m11.124s
user	0m0.371s
sys	0m2.748s

as #!/bin/ash .

takes twice time,
did not work for me to alias t=test

Overall result is that test is faster than [ ] ; and alias t=test is as fast as [ ] .