-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbench_script.sh
executable file
·45 lines (39 loc) · 1.09 KB
/
bench_script.sh
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
43
44
45
#!/bin/sh
# This env variable is here to permit
# to use a custom `cargo bench` command if needed
CARGO_BENCH_CMD=${CARGO_BENCH_CMD:-cargo bench --features unstable}
if [ $# -eq 0 ]; then
echo "comparing benchmarks of HEAD~1 and HEAD..."
OLD=$(git rev-parse --short 'HEAD~1')
NEW=$(git rev-parse --short 'HEAD')
elif [ $# -eq 1 ]; then
echo "comparing benchmarks of $1 and HEAD..."
OLD=$(git rev-parse --short $1)
NEW=$(git rev-parse --short 'HEAD')
elif [ $# -eq 2 ]; then
echo "comparing benchmarks of $1 and $2..."
OLD=$(git rev-parse --short $1)
NEW=$(git rev-parse --short $2)
else
echo 'Usage: bench_script.sh [$OLD] [$NEW]'
exit 1
fi
exit_if_dirty() {
if ! git diff-files --quiet; then
echo 'Your repository must not be dirty'
exit 1
fi
}
if [ ! -f $NEW.bench ]; then
exit_if_dirty
git checkout $NEW
$CARGO_BENCH_CMD > $NEW.bench
git checkout -
fi
if [ ! -f $OLD.bench ]; then
exit_if_dirty
git checkout $OLD
$CARGO_BENCH_CMD > $OLD.bench
git checkout -
fi
cargo benchcmp --threshold 5 $OLD.bench $NEW.bench