tobogganSe connecter

louise

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

94 lignes · 3592 octetsBrut · Historique
1#!/usr/bin/env bash
2# Compile-time benchmark (issue #61): `louise build` of the demo
3# (examples/http_demo) and of a std-heavy program
4# (tests/bench/compile/std_tour.lse), debug and release, each cold (into a
5# fresh directory) and warm (the same build again, unchanged). Reports the
6# best of N, in milliseconds of wall time. `louise build --timings` shows
7# where the time goes.
8#
9# scripts/bench-compile.sh # run, print a table
10# scripts/bench-compile.sh --save FILE # also save the results (name ms)
11# scripts/bench-compile.sh --compare FILE # also compare with saved results
12#
13# Environment: BENCH_RUNS (default 3); LOUISE, the compiler to time (default
14# target/$LOUISE_PROFILE/louise, built first), e.g. another version's;
15# LOUISE_PROFILE (release or dist, scripts/lib.sh); LOUISE_CC.
16set -euo pipefail
17cd "$(dirname "$0")/.."
18source scripts/lib.sh
19
20mode="${1:-}"
21file="${2:-}"
22runs="${BENCH_RUNS:-3}"
23if [ -z "${LOUISE:-}" ]; then
24 build_release_louise
25fi
26louise="${LOUISE:-$LOUISE_BIN}"
27out="$(mktemp -d)"
28trap 'rm -rf "$out"' EXIT
29
30# Milliseconds a build takes; fails if the build does.
31build_ms() {
32 local start
33 start=$(date +%s%N)
34 "$louise" build "$@" >/dev/null
35 echo $((($(date +%s%N) - start) / 1000000))
36}
37
38table_start "$mode" "$file" 22 build "$out/results"
39for target in examples/http_demo tests/bench/compile/std_tour.lse; do
40 name="$(basename "$target" .lse)"
41 for profile in debug release; do
42 flags=()
43 [ "$profile" = release ] && flags=(--release)
44 cold="" warm=""
45 for _ in $(seq "$runs"); do
46 # Cold: no build directory. A package's is in its root (ADR 0025).
47 rm -rf "$out/build"
48 if [ -d "$target" ]; then rm -rf "$target/build"; fi
49 c=$(build_ms "${flags[@]}" "$target" -o "$out/build/prog")
50 w=$(build_ms "${flags[@]}" "$target" -o "$out/build/prog")
51 if [ -z "$cold" ] || [ "$c" -lt "$cold" ]; then cold=$c; fi
52 if [ -z "$warm" ] || [ "$w" -lt "$warm" ]; then warm=$w; fi
53 done
54 table_row "$name-$profile-cold" "$cold"
55 table_row "$name-$profile-warm" "$warm"
56 done
57done
58
59# Switching profiles: both builds exist, so each reuses its objects
60# (ADR 0025 Revision 1, issue #112).
61switch=""
62"$louise" build examples/http_demo -o "$out/build/prog" >/dev/null
63"$louise" build --release examples/http_demo -o "$out/build/prog" >/dev/null
64for _ in $(seq "$runs"); do
65 s=$(build_ms examples/http_demo -o "$out/build/prog")
66 if [ -z "$switch" ] || [ "$s" -lt "$switch" ]; then switch=$s; fi
67 build_ms --release examples/http_demo -o "$out/build/prog" >/dev/null
68done
69table_row "http_demo-switch" "$switch"
70
71# An edit: one string literal changed in a copy of std_tour, then a debug
72# build (the C changes; the rest of the build is warm).
73cp tests/bench/compile/std_tour.lse "$out/edit.lse"
74"$louise" build "$out/edit.lse" -o "$out/build/edit" >/dev/null
75edit=""
76for i in $(seq "$runs"); do
77 sed -i "0,/println(\"/s//println(\"$i /" "$out/edit.lse"
78 e=$(build_ms "$out/edit.lse" -o "$out/build/edit")
79 if [ -z "$edit" ] || [ "$e" -lt "$edit" ]; then edit=$e; fi
80done
81table_row "std_tour-debug-edit" "$edit"
82
83# `louise test --native` of the demo, run again (issue #113).
84louise_abs="$(realpath "$louise")"
85(cd examples/http_demo && "$louise_abs" test --native >/dev/null) || true
86tests=""
87for _ in $(seq "$runs"); do
88 start=$(date +%s%N)
89 (cd examples/http_demo && "$louise_abs" test --native >/dev/null)
90 t=$((($(date +%s%N) - start) / 1000000))
91 if [ -z "$tests" ] || [ "$t" -lt "$tests" ]; then tests=$t; fi
92done
93table_row "http_demo-test-warm" "$tests"
94table_end