bench-cmd 602 B

12345678910111213141516171819
  1. #!/usr/bin/env bash
  2. # Benchmark a command as a string and output results
  3. # to a file with format:
  4. #
  5. # cmd <command run>
  6. # time <time in seconds to finish>
  7. # exit_status <exit status>
  8. set -eu
  9. root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
  10. # Command to benchmark
  11. cmd="$1"
  12. shift
  13. # Where to append write results to. Default: /dev/null.
  14. results_file="${1:-/dev/null}"
  15. mkdir -p "$(dirname "$results_file")"
  16. printf 'cmd ' >> "$results_file"
  17. env time --append -f 'time %e' --output="$results_file" "${root_dir}/eeval" -a "$cmd" "$results_file"
  18. printf "exit_status $?\n" >> "$results_file"