#!/usr/bin/env bash # Benchmarks (tests/bench/*.lse), built optimised. Each prints a checksum, # which must equal its `//>` lines (format: tests/README.md), so a faster # program is still a correct one. Reports the best of N runs, in # milliseconds. # # scripts/bench.sh # run, print a table # scripts/bench.sh --save FILE # also save the results (name ms) # scripts/bench.sh --compare FILE # also compare with saved results # # Environment: BENCH_RUNS (default 3), LOUISE_THREADS (the runtime's); # BENCH_PIN, a CPU list to pin the timed runs to with taskset (e.g. "0"), # for wall clock that does not wander with the scheduler (issue #193); # BENCH_BUILD_DIR, a directory to build the programs in and keep them # (scripts/bench-track.sh counts their instructions). set -euo pipefail cd "$(dirname "$0")/.." source scripts/lib.sh mode="${1:-}" file="${2:-}" runs="${BENCH_RUNS:-3}" build_release_louise if [ -n "${BENCH_BUILD_DIR:-}" ]; then out="$BENCH_BUILD_DIR" mkdir -p "$out" else out="$(mktemp -d)" trap 'rm -rf "$out"' EXIT fi table_start "$mode" "$file" 10 benchmark "$out/results" runner=() if [ -n "${BENCH_PIN:-}" ]; then runner=(taskset -c "$BENCH_PIN"); fi for program in tests/bench/*.lse; do name="$(basename "$program" .lse)" "$LOUISE_BIN" build --release "$program" -o "$out/$name" >/dev/null expected_output "$program" > "$out/$name.expected" best="" for _ in $(seq "$runs"); do start=$(date +%s%N) "${runner[@]}" "$out/$name" > "$out/$name.out" ms=$((($(date +%s%N) - start) / 1000000)) if ! diff -q "$out/$name.expected" "$out/$name.out" >/dev/null; then echo "bench: $name: wrong output"; diff -u "$out/$name.expected" "$out/$name.out"; exit 1 fi if [ -z "$best" ] || [ "$ms" -lt "$best" ]; then best=$ms; fi done table_row "$name" "$best" done table_end