hakermania
October 22nd, 2011, 07:20 AM
Hehehe, here you are:
alex@MaD-pc:~$ a=0; time while [ $a -lt 10000 ]; do let a=$a+1; done
real 0m0.217s
user 0m0.208s
sys 0m0.008s
alex@MaD-pc:~$ echo $a
10000
alex@MaD-pc:~$ a=0; time while [ $a -lt 10000 ]; do a=$(expr $a + 1); done
real 0m30.448s
user 0m1.540s
sys 0m5.088s
When I first started bash scripting I was told to use 'expr' so as to do a small addition to a variable but now I can see that it's much slower than 'let'.
From the above executions you can see that expr is 172 times slower (!) ;)
alex@MaD-pc:~$ a=0; time while [ $a -lt 10000 ]; do let a=$a+1; done
real 0m0.217s
user 0m0.208s
sys 0m0.008s
alex@MaD-pc:~$ echo $a
10000
alex@MaD-pc:~$ a=0; time while [ $a -lt 10000 ]; do a=$(expr $a + 1); done
real 0m30.448s
user 0m1.540s
sys 0m5.088s
When I first started bash scripting I was told to use 'expr' so as to do a small addition to a variable but now I can see that it's much slower than 'let'.
From the above executions you can see that expr is 172 times slower (!) ;)