Files
fastwc/benchmarks/files/words/bench.sh
T

33 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# bench.sh — race fastwc against GNU coreutils wc on word counts, file input.
# Busybox and toybox wc are raced too, for shits and giggles.
# Fails fast: the moment fastwc is slower than (or disagrees with) an
# oracle wc, a human readable report is written to FAILED-benchmark.txt
# and this script exits non-zero.
#
# usage: ./bench.sh
set -u
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_DIR="$(cd "$SCRIPT_DIR/../../.." && pwd)"
source "$REPO_DIR/benchmarks/std.sh"
checkfastwc
checkwc
for oracle in $ORACLES; do
select_oracle "$oracle" || exit 1
printf 'benchmarking %s wc vs fastwc: words, file input (%s interleaved runs each, minimum kept)\n' \
"$BENCH_NAME" "$BENCH_REPS"
printf '%-28s %16s %24s %8s %s\n' 'test' 'wc' 'fastwc (µs)' 'ratio' 'status'
printf '%s\n' '--- words ---'
if ! run_cases words -w 1 10 100 1000 10000 100000 1000000 10000000; then
exit 1
fi
printf '\nall %s words benchmarks passed — fastwc was never slower than %s wc\n' \
"$BENCH_NAME" "$BENCH_NAME"
done