Files
fastwc/benchmarks/files/lines/bench.sh
T
huntedbytheirs 55aab093e7 bench: report fastwc timing in microseconds
Sub-millisecond runs showed as a flat 0ms, hiding real differences. The
suite now times fastwc with a time_us helper, keeps the minimum reading
in µs, derives ms from it, and prints both (fastwc: 0ms (767µs)). GNU wc
stays at ms precision; solo case shows µs too.
2026-08-29 18:56:50 -04:00

39 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# bench.sh — race fastwc against GNU coreutils wc on line counts, file input.
# Includes the monster cases: 100M lines raced against coreutils, and 1B
# lines timed solo (no reference to beat — there isn't one).
# Fails fast: the moment fastwc is slower than (or disagrees with) coreutils
# 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
BENCH_NAME="coreutils"
printf 'benchmarking %s wc vs fastwc: lines, file input (%s interleaved runs each, minimum kept)\n' \
"$BENCH_NAME" "$BENCH_REPS"
printf '%-28s %10s %22s %8s %s\n' 'test' 'wc' 'fastwc (ms µs)' 'ratio' 'status'
printf '%s\n' '--- lines ---'
if ! run_cases lines -l 10000 100000 1000000 10000000; then
exit 1
fi
printf '%s\n' '--- monster: 100M lines vs coreutils ---'
if ! run_cases lines -l 100000000; then
exit 1
fi
printf '%s\n' '--- monster: 1B lines, solo ---'
run_solo_case 1000000000 -l
printf '\nall %s lines benchmarks passed — fastwc was never slower than %s wc\n' \
"$BENCH_NAME" "$BENCH_NAME"