#!/usr/bin/env bash # Compile-time benchmark (issue #61): `louise build` of the demo # (examples/http_demo) and of a std-heavy program # (tests/bench/compile/std_tour.lse), debug and release, each cold (into a # fresh directory) and warm (the same build again, unchanged). Reports the # best of N, in milliseconds of wall time. `louise build --timings` shows # where the time goes. # # scripts/bench-compile.sh # run, print a table # scripts/bench-compile.sh --save FILE # also save the results (name ms) # scripts/bench-compile.sh --compare FILE # also compare with saved results # # Environment: BENCH_RUNS (default 3); LOUISE, the compiler to time (default # target/$LOUISE_PROFILE/louise, built first), e.g. another version's; # LOUISE_PROFILE (release or dist, scripts/lib.sh); LOUISE_CC. set -euo pipefail cd "$(dirname "$0")/.." source scripts/lib.sh mode="${1:-}" file="${2:-}" runs="${BENCH_RUNS:-3}" if [ -z "${LOUISE:-}" ]; then build_release_louise fi louise="${LOUISE:-$LOUISE_BIN}" out="$(mktemp -d)" trap 'rm -rf "$out"' EXIT # Milliseconds a build takes; fails if the build does. build_ms() { local start start=$(date +%s%N) "$louise" build "$@" >/dev/null echo $((($(date +%s%N) - start) / 1000000)) } table_start "$mode" "$file" 22 build "$out/results" for target in examples/http_demo tests/bench/compile/std_tour.lse; do name="$(basename "$target" .lse)" for profile in debug release; do flags=() [ "$profile" = release ] && flags=(--release) cold="" warm="" for _ in $(seq "$runs"); do # Cold: no build directory. A package's is in its root (ADR 0025). rm -rf "$out/build" if [ -d "$target" ]; then rm -rf "$target/build"; fi c=$(build_ms "${flags[@]}" "$target" -o "$out/build/prog") w=$(build_ms "${flags[@]}" "$target" -o "$out/build/prog") if [ -z "$cold" ] || [ "$c" -lt "$cold" ]; then cold=$c; fi if [ -z "$warm" ] || [ "$w" -lt "$warm" ]; then warm=$w; fi done table_row "$name-$profile-cold" "$cold" table_row "$name-$profile-warm" "$warm" done done # Switching profiles: both builds exist, so each reuses its objects # (ADR 0025 Revision 1, issue #112). switch="" "$louise" build examples/http_demo -o "$out/build/prog" >/dev/null "$louise" build --release examples/http_demo -o "$out/build/prog" >/dev/null for _ in $(seq "$runs"); do s=$(build_ms examples/http_demo -o "$out/build/prog") if [ -z "$switch" ] || [ "$s" -lt "$switch" ]; then switch=$s; fi build_ms --release examples/http_demo -o "$out/build/prog" >/dev/null done table_row "http_demo-switch" "$switch" # An edit: one string literal changed in a copy of std_tour, then a debug # build (the C changes; the rest of the build is warm). cp tests/bench/compile/std_tour.lse "$out/edit.lse" "$louise" build "$out/edit.lse" -o "$out/build/edit" >/dev/null edit="" for i in $(seq "$runs"); do sed -i "0,/println(\"/s//println(\"$i /" "$out/edit.lse" e=$(build_ms "$out/edit.lse" -o "$out/build/edit") if [ -z "$edit" ] || [ "$e" -lt "$edit" ]; then edit=$e; fi done table_row "std_tour-debug-edit" "$edit" # `louise test --native` of the demo, run again (issue #113). louise_abs="$(realpath "$louise")" (cd examples/http_demo && "$louise_abs" test --native >/dev/null) || true tests="" for _ in $(seq "$runs"); do start=$(date +%s%N) (cd examples/http_demo && "$louise_abs" test --native >/dev/null) t=$((($(date +%s%N) - start) / 1000000)) if [ -z "$tests" ] || [ "$t" -lt "$tests" ]; then tests=$t; fi done table_row "http_demo-test-warm" "$tests" table_end