Files
fastwc/benchmarks/files/words/bench.sh
T
huntedbytheirs c45de29b0c Race the UTF-8 decoder against coreutils
Every case in the suite pinned LC_ALL=C, so the multibyte path - the one
whose counts go wrong quietly rather than crashing - had no contract
behind it at all. genfile grew a --utf8 mode that writes mixed CJK,
ASCII words, a tab, an ideographic space, a no-break space and a
combining accent, and the words suite now races -w, -m and -L over 300k
lines of it under en_US.UTF-8 (C.UTF-8 as a fallback), against coreutils.

The case runs the locale on both sides rather than inheriting the C pin,
because the oracle's own decoder is the reference. It prints SKIP rather
than passing when the host has no UTF-8 locale: a multibyte count cannot
be checked in a single-byte one.
2026-11-15 14:00:07 -05:00

49 lines
1.6 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
# The multibyte path, raced against coreutils only: under a UTF-8 locale
# wc decodes, and the case is about our decoder agreeing with its counts
# and beating its speed. 300k mixed lines is about 6 MB, which is enough
# for both sides to be counting rather than starting.
select_oracle coreutils || exit 1
printf '\n%s\n' '--- multibyte, UTF-8 locale (coreutils) ---'
if ! run_utf8_case words 300000 -w; then
exit 1
fi
if ! run_utf8_case chars 300000 -m; then
exit 1
fi
if ! run_utf8_case 'longest line' 300000 -L; then
exit 1
fi