forked from fmerg/pymerkle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.sh
executable file
·177 lines (152 loc) · 4.29 KB
/
benchmark.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
DEFAULT_DBFILE="./benchmarks/merkle.db"
DEFAULT_BENCHMARK="benchmarks/test_perf.py"
DEFAULT_SIZE=$((10 ** 6))
DEFAULT_ROUNDS=100
DEFAULT_THRESHOLD=128
DEFAULT_CAPACITY=$((1024 ** 3))
DEFAULT_ALGORITHM=sha256
DEFAULT_OPERATION=""
DEFAULT_SAVE=true
usage_string="
usage: ./$(basename "$0") [options]
Run benchmarks against ${DEFAULT_DBFILE}
Results saved in ./.bencmarks/Linux-CPyhton-3.*
Tree configuration
--algorithm HASH Hash algorithm used by the tree (default: ${DEFAULT_ALGORITHM})
--threshold WIDTH Subroot cache threshold (default: ${DEFAULT_THRESHOLD})
--capacity MAXSIZE Subroout cache capacity in bytes (default: 1GiB)
--disable-optimizations Use unoptimized version of core operations
--disable-cache Disable caching
Benchmarking options
--dbfile DB Database to use (default: ${DEFAULT_DBFILE})
--operation OP Benchmark a single operation: root, state, inclusion,
consistency. If not provided, it benchmarks everything
--size SIZE Nr entries to consider (default: ${DEFAULT_SIZE})
--index INDEX Base index for proof operations. If not provided,
it will be set equal to ceil(size/2)
--rounds ROUNDS Nr rounds per benchmark (default: ${DEFAULT_ROUNDS})
-r, --randomize Randomize function input per round. Useful for
capturing the effect of caching. WARNING: This will
nullify the effect of the index option
-c, --compare Compare against last saved benchmark
-ss, --skip-save Do not save results
-h, --help Display help message and exit
Examples:
$ ./benchmark.sh --rounds 10 --skip-save --size 1000000 --randomize --disable-optimizations
$ ./benchmark.sh --rounds 10 --skip-save --size 1000000 --randomize --disable-cache
$ ./benchmark.sh --rounds 10 --skip-save --size 1000000 --randomize
"
set -e
usage() { echo -n "$usage_string" 1>&2; }
DBFILE="$DEFAULT_DBFILE"
BENCHMARK="$DEFAULT_BENCHMARK"
SIZE="$DEFAULT_SIZE"
ROUNDS="$DEFAULT_ROUNDS"
THRESHOLD="$DEFAULT_THRESHOLD"
CAPACITY="$DEFAULT_CAPACITY"
ALGORITHM="$DEFAULT_ALGORITHM"
OPERATION="$DEFAULT_OPERATION"
SAVE="$DEFAULT_SAVE"
opts=()
while [[ $# -gt 0 ]]
do
arg="$1"
case $arg in
--dbfile)
DBFILE="$2"
shift
shift
;;
--size)
SIZE="$2"
shift
shift
;;
--index)
INDEX="$2"
shift
shift
;;
--rounds)
ROUNDS="$2"
shift
shift
;;
--algorithm)
ALGORITHM="$2"
shift
shift
;;
--threshold)
THRESHOLD="$2"
shift
shift
;;
--capacity)
CAPACITY="$2"
shift
shift
;;
--operation)
OPERATION="$2"
shift
shift
;;
--disable-optimizations)
opts+=" $arg"
shift
;;
--disable-cache)
opts+=" $arg"
shift
;;
-r|--randomize)
opts+=" $arg"
shift
;;
-c|--compare)
opts+=(--benchmark-compare)
shift
;;
-ss|--skip-save)
SAVE=false
shift
;;
-h|--help)
usage
exit 0
;;
*)
opts+=" $arg"
shift
;;
esac
done
if [ ! -f "$DBFILE" ]; then
echo "No database found at ${DBFILE}"
exit 1
fi
if [ -z ${INDEX} ]; then
INDEX=$(($(($SIZE + 1))/2))
fi
if [ ${OPERATION} ]; then
BENCHMARK="${BENCHMARK}::test_${OPERATION}"
fi
if [ ${SAVE} == true ]; then
opts+=" --benchmark-autosave"
fi
python -m pytest $BENCHMARK \
--dbfile $DBFILE \
--size $SIZE \
--index $INDEX \
--rounds $ROUNDS \
--algorithm $ALGORITHM \
--threshold $THRESHOLD \
--capacity $CAPACITY \
--quiet \
--benchmark-only \
--benchmark-name=short \
--benchmark-warmup=off \
--benchmark-columns=min,max,mean,median,outliers,rounds,ops \
$opts