Size: 1468
Comment:
|
Size: 1487
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 16: | Line 16: |
As though you didn't already have enough reason to dump `expr`. |
|
Line 25: | Line 23: |
Another good reason to always quote your expansions. | == Multiple Arguments == || 0m0.642s || {{{i=( {1..100000} ); time { echo "${i[@]}" >/dev/null; } }}} || || 0m3.112s || {{{printf -v i '%s ' {1..100000}; time { echo $i >/dev/null; } }}} || |
Line 34: | Line 36: |
`[[` isn't just more featureful, it's also twice as fast. |
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 |
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; } |
Multiple Arguments
0m0.642s |
i=( {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 |