LWN.net Logo

Test, with "test" vs /usr/bin/test

Test, with "test" vs /usr/bin/test

Posted Jul 25, 2006 3:59 UTC (Tue) by Richard_J_Neill (subscriber, #23093)
In reply to: OLS: On how user space sucks by cjwatson
Parent article: OLS: On how user space sucks

"if [ a = b ] " and "if test a = b " are both shell-builtins. If you want the other one, you have to call /usr/bin/test

$ date; for ((i=0; i<10000; i++)) ; do if [ a = b ] ; then c=d ; fi ; done ;date
Tue Jul 25 04:51:16 BST 2006
Tue Jul 25 04:51:16 BST 2006

$ date; for ((i=0; i<10000; i++)) ; do if test a = b ; then c=d ; fi ; done ;date
Tue Jul 25 04:51:27 BST 2006
Tue Jul 25 04:51:27 BST 2006

$ date; for ((i=0; i<10000; i++)) ; do if /usr/bin/test a = b ; then c=d ; fi ; done ;date
Tue Jul 25 04:51:33 BST 2006
Tue Jul 25 04:51:50 BST 2006

It's a huge difference! The script with the builtins runs 60 times faster.


(Log in to post comments)

Test, with "test" vs /usr/bin/test

Posted Jul 29, 2006 15:43 UTC (Sat) by kreutzm (subscriber, #4700) [Link]

Where do you see that "60x"? ALso I'd advise you to use time(1) next time ;-)

Copyright © 2008, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds