| 1 | #!/usr/bin/env bash
|
| 2 | #
|
| 3 | # Synthetic shell benchmarks
|
| 4 | #
|
| 5 | # Usage:
|
| 6 | # testdata/osh-runtime/bin_true.sh <function name>
|
| 7 |
|
| 8 | # Run under:
|
| 9 | # - benchmarks/uftrace to trace allocations
|
| 10 | # - benchmarks/osh-runtime for wall time and GC stats
|
| 11 |
|
| 12 | # make sure we can run under dash
|
| 13 |
|
| 14 | #set -o nounset
|
| 15 | #set -o pipefail
|
| 16 | #set -o errexit
|
| 17 |
|
| 18 | main() {
|
| 19 | local n=${1:-1000}
|
| 20 |
|
| 21 | echo "Running /bin/true $n times"
|
| 22 |
|
| 23 | local i=0
|
| 24 | while test $i -lt $n; do
|
| 25 | /bin/true
|
| 26 | i=$(( i + 1 ))
|
| 27 | done
|
| 28 |
|
| 29 | echo 'Done'
|
| 30 | }
|
| 31 |
|
| 32 | # Other tests we can do:
|
| 33 | # - Subshell
|
| 34 | # - Pipeline
|
| 35 |
|
| 36 | main "$@"
|