Skip to content

Instantly share code, notes, and snippets.

@cympfh
Created July 17, 2015 16:50
Show Gist options
  • Save cympfh/392cf1fbf9741f3392db to your computer and use it in GitHub Desktop.
Save cympfh/392cf1fbf9741f3392db to your computer and use it in GitHub Desktop.
#!/bin/bash
echo expr
time ( for t in `seq 100`; do
prod=1
for i in `seq 1 10`; do
prod=`expr $prod \\* $i`
done
done ) 2>&1
echo
echo "\$(())"
time ( for t in `seq 100`; do
prod=1
for i in `seq 1 10`; do
prod=$(( $prod * $i ))
done
done ) 2>&1
echo
echo let
time ( for t in `seq 100`; do
prod=1
for i in `seq 1 10`; do
let "prod = prod * i"
done
done ) 2>&1
echo
echo bc
time ( for t in `seq 100`; do
prod=1
for i in `seq 1 10`; do
prod=`echo $prod \\* $i | bc`
done
done ) 2>&1
echo
cat << EOM
# result
expr
real 0m0.631s
user 0m0.040s
sys 0m0.638s
$(())
real 0m0.063s
user 0m0.001s
sys 0m0.067s
let
real 0m0.065s
user 0m0.012s
sys 0m0.057s
bc
real 0m1.010s
user 0m0.063s
sys 0m1.255s
EOM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment