/
membench-bisect
42 lines (32 loc) · 1.35 KB
/
membench-bisect
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/sh
set -xeu
precision=${1:-25000}
start_fail=${2:-6000000}
start_pass=${3:-16000000}
iteration=0
while true
do if test -f 'membench-last-fail.json'
then last_fail=$(jq '.memLimit' 'membench-last-fail.json')
else last_fail=$start_fail; fi
if test -f 'membench-last-pass.json'
then last_pass=$(jq '.memLimit' 'membench-last-pass.json')
else last_pass=$start_pass; fi
outcome_gap=$(($last_pass - $last_fail))
echo "membench: pass/fail outcome gap: $outcome_gap"
if test $outcome_gap -le $precision
then echo "membench: outcome gap below precision $precision, terminating"; exit 0
else echo "membench: outcome gap above precision $precision, next iteration"; fi
nextLimit=$((($last_fail + $last_pass) / 2))
echo "{ memLimit: $nextLimit }" > 'membench-limit.json'
time nix build '.#membench' -L --out-link 'membench-last'
# nix-store -r $(readlink ./result) --add-root 'membench-last' --indirect
lastResult=$(jq .failed 'result/refined.json')
if [ x$lastResult = xfalse ]
then outcome=pass
else outcome=fail; fi
cp -f 'membench-last/refined.json' 'membench-last-'$outcome'.json'
rm -f 'membench-last-'$outcome; mv 'membench-last' 'membench-last-'$outcome
echo "--------------------------------- iteration $iteration boundaries:"
jq . 'membench-last-fail.json'
jq . 'membench-last-pass.json'
done