···
48
-
# TODO: Measure time
50
-
NIX_PATH=nixpkgs=$1 NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH=$tmp/stats.json \
51
-
nix-instantiate --eval --strict --show-trace >/dev/null \
52
-
--expr 'with import <nixpkgs/lib>; with fileset; '"$2"
53
-
cat "$tmp/stats.json"
54
+
for i in $(seq 0 "$runs"); do
55
+
NIX_PATH=nixpkgs=$1 NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH=$tmp/stats.json \
56
+
nix-instantiate --eval --strict --show-trace >/dev/null \
57
+
--expr 'with import <nixpkgs/lib>; with fileset; '"$2"
59
+
# Only measure the time after the first run, one is warmup
60
+
if (( i > 0 )); then
61
+
jq '.cpuTime' "$tmp/stats.json" >> cpuTimes
65
+
# Compute mean and standard deviation
66
+
read -r mean sd < <(sta --mean --sd --brief <cpuTimes)
68
+
jq --argjson mean "$mean" --argjson sd "$sd" \
69
+
'.cpuTimeMean = $mean | .cpuTimeSd = $sd' \
···
#echo "Running benchmark on $compareTo" >&2
run "$tmp/worktree" "$1" > "$tmp/old.json"
85
+
read -r oldMean oldSd newMean newSd percentageMean percentageSd < \
86
+
<(jq -rn --slurpfile old "$tmp/old.json" --slurpfile new "$tmp/new.json" \
87
+
' $old[0].cpuTimeMean as $om
88
+
| $old[0].cpuTimeSd as $os
89
+
| $new[0].cpuTimeMean as $nm
90
+
| $new[0].cpuTimeSd as $ns
91
+
| (100 / $om * $nm) as $pm
92
+
# Copied from https://github.com/sharkdp/hyperfine/blob/b38d550b89b1dab85139eada01c91a60798db9cc/src/benchmark/relative_speed.rs#L46-L53
93
+
| ($pm * pow(pow($ns / $nm; 2) + pow($os / $om; 2); 0.5)) as $ps
94
+
| [ $om, $os, $nm, $ns, $pm, $ps ]
97
+
echo -e "Mean CPU time $newMean (σ = $newSd) for $runs runs is \e[0;33m$percentageMean% (σ = $percentageSd%)\e[0m of the old value $oldMean (σ = $oldSd)" >&2
for stat in "${stats[@]}"; do