Some rough benchmarks
To compare different approaches to a problem with regards to performance, here's some rough benchmarks which may be system-dependent. Feel free to run each test yourself to see how your system fares.
Results are always sorted with the winners on top. All tests were repeated multiple times to make sure deviations did not exceed acceptable levels or cross result boundaries.
Math
Time |
Code |
0m1.153s |
j=0; time for i in {1..100000}; do ((j++)); done |
0m1.381s |
j=0; time for i in {1..100000}; do j=$((j+1)); done |
0m1.498s |
j=0; time for i in {1..100000}; do let j++; done |
5m8.448s |
j=0; time for i in {1..100000}; do j=$(expr $j + 1); done |
Quoting
Time |
Code |
0m0.642s |
i=( {1..100000} ); time { echo "${i[@]}" >/dev/null; } |
0m1.538s |
printf -v i '%s ' {1..100000}; time { echo "$i" >/dev/null; } |
0m3.112s |
printf -v i '%s ' {1..100000}; time { echo $i >/dev/null; } |
Testing
Time |
Code |
0m1.099s |
time for i in {1..100000}; do [[ -d . ]]; done |
0m2.110s |
time for i in {1..100000}; do [ -d . ]; done |
3m47.509s |
time for i in {1..100000}; do /bin/test -d .; done |