tobogganSe connecter

louise

The Louise language: compiler, runtime, std, tooling

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

51 lignes · 1861 octetsBrut · Historique
1#!/usr/bin/env bash
2# Benchmarks (tests/bench/*.lse), built optimised. Each prints a checksum,
3# which must equal its `//>` lines (format: tests/README.md), so a faster
4# program is still a correct one. Reports the best of N runs, in
5# milliseconds.
6#
7# scripts/bench.sh # run, print a table
8# scripts/bench.sh --save FILE # also save the results (name ms)
9# scripts/bench.sh --compare FILE # also compare with saved results
10#
11# Environment: BENCH_RUNS (default 3), LOUISE_THREADS (the runtime's);
12# BENCH_PIN, a CPU list to pin the timed runs to with taskset (e.g. "0"),
13# for wall clock that does not wander with the scheduler (issue #193);
14# BENCH_BUILD_DIR, a directory to build the programs in and keep them
15# (scripts/bench-track.sh counts their instructions).
16set -euo pipefail
17cd "$(dirname "$0")/.."
18source scripts/lib.sh
19
20mode="${1:-}"
21file="${2:-}"
22runs="${BENCH_RUNS:-3}"
23build_release_louise
24if [ -n "${BENCH_BUILD_DIR:-}" ]; then
25 out="$BENCH_BUILD_DIR"
26 mkdir -p "$out"
27else
28 out="$(mktemp -d)"
29 trap 'rm -rf "$out"' EXIT
30fi
31
32table_start "$mode" "$file" 10 benchmark "$out/results"
33runner=()
34if [ -n "${BENCH_PIN:-}" ]; then runner=(taskset -c "$BENCH_PIN"); fi
35for program in tests/bench/*.lse; do
36 name="$(basename "$program" .lse)"
37 "$LOUISE_BIN" build --release "$program" -o "$out/$name" >/dev/null
38 expected_output "$program" > "$out/$name.expected"
39 best=""
40 for _ in $(seq "$runs"); do
41 start=$(date +%s%N)
42 "${runner[@]}" "$out/$name" > "$out/$name.out"
43 ms=$((($(date +%s%N) - start) / 1000000))
44 if ! diff -q "$out/$name.expected" "$out/$name.out" >/dev/null; then
45 echo "bench: $name: wrong output"; diff -u "$out/$name.expected" "$out/$name.out"; exit 1
46 fi
47 if [ -z "$best" ] || [ "$ms" -lt "$best" ]; then best=$ms; fi
48 done
49 table_row "$name" "$best"
50done
51table_end