Skip to content

Commit ebf3d64

Browse files
committed
doc: add batch verification speedup graph
1 parent 9375645 commit ebf3d64

File tree

9 files changed

+263
-2
lines changed

9 files changed

+263
-2
lines changed

doc/speedup-batch.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Schnorrsig Batch Verification Speedup
2+
3+
![Speedup over single verification](speedup-batch/speedup-batch.png)
4+

doc/speedup-batch/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
batch.dat
2+
single.dat

doc/speedup-batch/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
bench_output.txt: bench.sh
2+
SECP256K1_BENCH_ITERS=500000 ./bench.sh bench_output.txt
3+
4+
batch.dat: bench_output.txt
5+
cat bench_output.txt | grep -v "schnorrsig_batch_verify_1:" | gawk 'match($$0, /schnorrsig_batch_verify_(.*):.*avg (.*)us /, a) {print a[1] " " a[2]}' > batch.dat
6+
7+
single.dat: bench_output.txt
8+
cat bench_output.txt | awk 'match($$0, /schnorrsig_verify:.*avg (.*)us /, a) {print a[1]}' > single.dat
9+
10+
speedup-batch.png: batch.dat single.dat plot.p
11+
gnuplot plot.p

doc/speedup-batch/bench.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
output_file=$1
4+
cur_dir=$(pwd)
5+
6+
cd ../../
7+
echo "HEAD: $(git rev-parse --short HEAD)" > "$cur_dir/$output_file.log"
8+
make clean
9+
./autogen.sh
10+
./configure --enable-experimental --enable-module-schnorrsig >> "$cur_dir/$output_file.log"
11+
make -j
12+
./bench_schnorrsig > "$cur_dir/$output_file"
13+

doc/speedup-batch/bench_output.txt

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
schnorrsig_sign: min 24.3us / avg 24.3us / max 24.3us
2+
schnorrsig_verify: min 41.7us / avg 41.7us / max 41.8us
3+
schnorrsig_batch_verify_1: min 47.6us / avg 47.6us / max 47.6us
4+
schnorrsig_batch_verify_2: min 39.4us / avg 39.4us / max 39.5us
5+
schnorrsig_batch_verify_3: min 39.0us / avg 39.0us / max 39.0us
6+
schnorrsig_batch_verify_4: min 37.4us / avg 37.4us / max 37.4us
7+
schnorrsig_batch_verify_5: min 37.6us / avg 37.7us / max 37.7us
8+
schnorrsig_batch_verify_7: min 37.0us / avg 37.1us / max 37.1us
9+
schnorrsig_batch_verify_9: min 36.6us / avg 36.7us / max 36.7us
10+
schnorrsig_batch_verify_11: min 35.5us / avg 35.5us / max 35.5us
11+
schnorrsig_batch_verify_14: min 36.0us / avg 36.0us / max 36.1us
12+
schnorrsig_batch_verify_17: min 37.1us / avg 37.1us / max 37.1us
13+
schnorrsig_batch_verify_21: min 35.9us / avg 35.9us / max 35.9us
14+
schnorrsig_batch_verify_26: min 36.1us / avg 36.1us / max 36.1us
15+
schnorrsig_batch_verify_32: min 36.4us / avg 36.4us / max 36.4us
16+
schnorrsig_batch_verify_39: min 36.0us / avg 36.0us / max 36.0us
17+
schnorrsig_batch_verify_47: min 34.9us / avg 34.9us / max 34.9us
18+
schnorrsig_batch_verify_57: min 32.8us / avg 32.8us / max 32.8us
19+
schnorrsig_batch_verify_69: min 34.0us / avg 34.0us / max 34.0us
20+
schnorrsig_batch_verify_83: min 32.4us / avg 32.4us / max 32.4us
21+
schnorrsig_batch_verify_100: min 31.3us / avg 31.3us / max 31.3us
22+
schnorrsig_batch_verify_121: min 31.1us / avg 31.1us / max 31.2us
23+
schnorrsig_batch_verify_146: min 30.3us / avg 30.4us / max 30.4us
24+
schnorrsig_batch_verify_176: min 29.2us / avg 29.3us / max 29.3us
25+
schnorrsig_batch_verify_212: min 28.4us / avg 28.4us / max 28.4us
26+
schnorrsig_batch_verify_255: min 27.7us / avg 27.7us / max 27.8us
27+
schnorrsig_batch_verify_307: min 27.3us / avg 27.3us / max 27.3us
28+
schnorrsig_batch_verify_369: min 26.7us / avg 26.8us / max 26.8us
29+
schnorrsig_batch_verify_443: min 26.3us / avg 26.3us / max 26.3us
30+
schnorrsig_batch_verify_532: min 26.0us / avg 26.0us / max 26.0us
31+
schnorrsig_batch_verify_639: min 26.1us / avg 26.1us / max 26.1us
32+
schnorrsig_batch_verify_767: min 25.5us / avg 25.5us / max 25.5us
33+
schnorrsig_batch_verify_921: min 24.9us / avg 25.0us / max 25.0us
34+
schnorrsig_batch_verify_1106: min 24.5us / avg 24.5us / max 24.6us
35+
schnorrsig_batch_verify_1328: min 24.1us / avg 24.1us / max 24.1us
36+
schnorrsig_batch_verify_1594: min 23.8us / avg 23.8us / max 23.8us
37+
schnorrsig_batch_verify_1913: min 23.4us / avg 23.5us / max 23.5us
38+
schnorrsig_batch_verify_2296: min 23.4us / avg 23.4us / max 23.4us
39+
schnorrsig_batch_verify_2756: min 23.0us / avg 23.0us / max 23.0us
40+
schnorrsig_batch_verify_3308: min 22.7us / avg 22.7us / max 22.8us
41+
schnorrsig_batch_verify_3970: min 22.8us / avg 22.8us / max 22.8us
42+
schnorrsig_batch_verify_4765: min 22.4us / avg 22.5us / max 22.5us
43+
schnorrsig_batch_verify_5719: min 22.1us / avg 22.1us / max 22.1us
44+
schnorrsig_batch_verify_6863: min 21.9us / avg 21.9us / max 21.9us
45+
schnorrsig_batch_verify_8236: min 21.7us / avg 21.8us / max 21.8us
46+
schnorrsig_batch_verify_9884: min 21.5us / avg 21.5us / max 21.5us
47+
schnorrsig_batch_verify_11861: min 21.2us / avg 21.2us / max 21.2us
48+
schnorrsig_batch_verify_14234: min 21.0us / avg 21.1us / max 21.1us
49+
schnorrsig_batch_verify_17081: min 20.9us / avg 20.9us / max 20.9us
50+
schnorrsig_batch_verify_20498: min 20.8us / avg 20.8us / max 20.8us
51+
schnorrsig_batch_verify_24598: min 20.6us / avg 20.6us / max 20.6us
52+
schnorrsig_batch_verify_29518: min 20.5us / avg 20.6us / max 20.6us
53+
schnorrsig_batch_verify_35422: min 20.5us / avg 20.5us / max 20.5us
54+
schnorrsig_batch_verify_42507: min 20.4us / avg 20.4us / max 20.4us
55+
schnorrsig_batch_verify_51009: min 20.3us / avg 20.3us / max 20.3us
56+
schnorrsig_batch_verify_61211: min 20.3us / avg 20.3us / max 20.3us
57+
schnorrsig_batch_verify_73454: min 20.2us / avg 20.2us / max 20.3us
58+
schnorrsig_batch_verify_88145: min 20.2us / avg 20.2us / max 20.3us
59+
schnorrsig_batch_verify_105775: min 20.2us / avg 20.2us / max 20.2us
60+
schnorrsig_batch_verify_126931: min 20.2us / avg 20.2us / max 20.2us
61+
schnorrsig_batch_verify_152318: min 20.1us / avg 20.1us / max 20.2us
62+
schnorrsig_batch_verify_182782: min 20.1us / avg 20.1us / max 20.1us
63+
schnorrsig_batch_verify_219339: min 20.1us / avg 20.1us / max 20.1us
64+
schnorrsig_batch_verify_263207: min 20.1us / avg 20.1us / max 20.1us
65+
schnorrsig_batch_verify_315849: min 20.1us / avg 20.1us / max 20.1us
66+
schnorrsig_batch_verify_379019: min 20.1us / avg 20.1us / max 20.2us
67+
schnorrsig_batch_verify_454823: min 20.1us / avg 20.1us / max 20.1us
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
HEAD: e36209d1
2+
checking build system type... x86_64-pc-linux-gnu
3+
checking host system type... x86_64-pc-linux-gnu
4+
checking for a BSD-compatible install... /usr/bin/install -c
5+
checking whether build environment is sane... yes
6+
checking for a race-free mkdir -p... /usr/bin/mkdir -p
7+
checking for gawk... gawk
8+
checking whether make sets $(MAKE)... yes
9+
checking whether make supports nested variables... yes
10+
checking how to print strings... printf
11+
checking whether make supports the include directive... yes (GNU style)
12+
checking for gcc... gcc
13+
checking whether the C compiler works... yes
14+
checking for C compiler default output file name... a.out
15+
checking for suffix of executables...
16+
checking whether we are cross compiling... no
17+
checking for suffix of object files... o
18+
checking whether the compiler supports GNU C... yes
19+
checking whether gcc accepts -g... yes
20+
checking for gcc option to enable C11 features... none needed
21+
checking whether gcc understands -c and -o together... yes
22+
checking dependency style of gcc... gcc3
23+
checking for a sed that does not truncate output... /usr/bin/sed
24+
checking for grep that handles long lines and -e... /usr/bin/grep
25+
checking for egrep... /usr/bin/grep -E
26+
checking for fgrep... /usr/bin/grep -F
27+
checking for ld used by gcc... /usr/bin/ld
28+
checking if the linker (/usr/bin/ld) is GNU ld... yes
29+
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
30+
checking the name lister (/usr/bin/nm -B) interface... BSD nm
31+
checking whether ln -s works... yes
32+
checking the maximum length of command line arguments... 1572864
33+
checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop
34+
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
35+
checking for /usr/bin/ld option to reload object files... -r
36+
checking for objdump... objdump
37+
checking how to recognize dependent libraries... pass_all
38+
checking for dlltool... no
39+
checking how to associate runtime and link libraries... printf %s\n
40+
checking for ar... ar
41+
checking for archiver @FILE support... @
42+
checking for strip... strip
43+
checking for ranlib... ranlib
44+
checking command to parse /usr/bin/nm -B output from gcc object... ok
45+
checking for sysroot... no
46+
checking for a working dd... /usr/bin/dd
47+
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
48+
checking for mt... no
49+
checking if : is a manifest tool... no
50+
checking for stdio.h... yes
51+
checking for stdlib.h... yes
52+
checking for string.h... yes
53+
checking for inttypes.h... yes
54+
checking for stdint.h... yes
55+
checking for strings.h... yes
56+
checking for sys/stat.h... yes
57+
checking for sys/types.h... yes
58+
checking for unistd.h... yes
59+
checking for dlfcn.h... yes
60+
checking for objdir... .libs
61+
checking if gcc supports -fno-rtti -fno-exceptions... no
62+
checking for gcc option to produce PIC... -fPIC -DPIC
63+
checking if gcc PIC flag -fPIC -DPIC works... yes
64+
checking if gcc static flag -static works... yes
65+
checking if gcc supports -c -o file.o... yes
66+
checking if gcc supports -c -o file.o... (cached) yes
67+
checking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
68+
checking whether -lc should be explicitly linked in... no
69+
checking dynamic linker characteristics... GNU/Linux ld.so
70+
checking how to hardcode library paths into programs... immediate
71+
checking whether stripping libraries is possible... yes
72+
checking if libtool supports shared libraries... yes
73+
checking whether to build shared libraries... yes
74+
checking whether to build static libraries... yes
75+
checking whether make supports nested variables... (cached) yes
76+
checking for pkg-config... /usr/bin/pkg-config
77+
checking pkg-config is at least version 0.9.0... yes
78+
checking for ar... /usr/bin/ar
79+
checking for ranlib... /usr/bin/ranlib
80+
checking for strip... /usr/bin/strip
81+
checking dependency style of gcc... gcc3
82+
checking if gcc supports -std=c89 -pedantic -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wundef -Wno-unused-function -Wno-long-long -Wno-overlength-strings... yes
83+
checking if gcc supports -fvisibility=hidden... yes
84+
checking for valgrind/memcheck.h... yes
85+
checking for x86_64 assembly availability... yes
86+
checking for CRYPTO... yes
87+
checking for main in -lcrypto... yes
88+
checking for EC functions in libcrypto... yes
89+
configure: ******
90+
configure: WARNING: experimental build
91+
configure: Experimental features do not have stable APIs or properties, and may not be safe for production use.
92+
configure: Building extrakeys module: yes
93+
configure: Building schnorrsig module: yes
94+
configure: ******
95+
checking that generated files are newer than configure... done
96+
configure: creating ./config.status
97+
config.status: creating Makefile
98+
config.status: creating libsecp256k1.pc
99+
config.status: creating src/libsecp256k1-config.h
100+
config.status: src/libsecp256k1-config.h is unchanged
101+
config.status: executing depfiles commands
102+
config.status: executing libtool commands
103+
104+
Build Options:
105+
with ecmult precomp = yes
106+
with external callbacks = no
107+
with benchmarks = yes
108+
with tests = yes
109+
with openssl tests = yes
110+
with coverage = no
111+
module ecdh = no
112+
module recovery = no
113+
module extrakeys = yes
114+
module schnorrsig = yes
115+
116+
asm = x86_64
117+
ecmult window size = 15
118+
ecmult gen prec. bits = 4
119+
120+
valgrind = yes
121+
CC = gcc
122+
CFLAGS = -O2 -fvisibility=hidden -std=c89 -pedantic -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wundef -Wno-unused-function -Wno-long-long -Wno-overlength-strings -W -g
123+
CPPFLAGS =
124+
LDFLAGS =
125+
126+
CC_FOR_BUILD = gcc
127+
CFLAGS_FOR_BUILD = -O2 -fvisibility=hidden -std=c89 -pedantic -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wundef -Wno-unused-function -Wno-long-long -Wno-overlength-strings -W -g
128+
CPPFLAGS_FOR_BUILD =
129+
LDFLAGS_FOR_BUILD =

doc/speedup-batch/plot.p

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
set style line 80 lt rgb "#808080"
2+
set style line 81 lt 0
3+
set style line 81 lt rgb "#808080"
4+
set grid back linestyle 81
5+
set border 3 back linestyle 80
6+
set xtics nomirror
7+
set ytics nomirror
8+
set style line 1 lt rgb "#A00000" lw 2 pt 1
9+
set style line 2 lt rgb "#00A000" lw 2 pt 6
10+
set style line 3 lt rgb "#5060D0" lw 2 pt 2
11+
set style line 4 lt rgb "#F25900" lw 2 pt 9
12+
set key bottom right
13+
set autoscale
14+
unset log
15+
unset label
16+
set xtic auto
17+
set ytic auto
18+
set title "Batch signature verification in libsecp256k1"
19+
set xlabel "Number of signatures (logarithmic)"
20+
set ylabel "Verification time per signature in us"
21+
set grid
22+
set logscale x
23+
set mxtics 10
24+
25+
single_val=system("cat single.dat")
26+
set xrange [1.1:]
27+
set xtics add ("2" 2)
28+
set yrange [0.9:]
29+
set ytics -1,0.1,3
30+
set ylabel "Speedup over single verification"
31+
set term png size 800,600
32+
set output 'speedup-batch.png'
33+
plot "batch.dat" using 1:(single_val/$2) with points title "" ls 1

doc/speedup-batch/speedup-batch.png

10.1 KB
Loading

src/bench_schnorrsig.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ int main(void) {
7676
data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY | SECP256K1_CONTEXT_SIGN);
7777
/* Scratch space size was selected to allow fitting the maximum number of
7878
* points for the default iters value into a single ecmult_multi batch. */
79-
data.scratch = secp256k1_scratch_space_create(data.ctx, 7 * 1024 * 1024);
79+
/* TODO: this value was updated to support 100 times that */
80+
data.scratch = secp256k1_scratch_space_create(data.ctx, 700 * 1024 * 1024);
8081
data.keypairs = (const secp256k1_keypair **)malloc(iters * sizeof(secp256k1_keypair *));
8182
data.pk = (const unsigned char **)malloc(iters * sizeof(unsigned char *));
8283
data.msgs = (const unsigned char **)malloc(iters * sizeof(unsigned char *));
@@ -109,14 +110,15 @@ int main(void) {
109110

110111
run_benchmark("schnorrsig_sign", bench_schnorrsig_sign, NULL, NULL, (void *) &data, 10, iters);
111112
run_benchmark("schnorrsig_verify", bench_schnorrsig_verify, NULL, NULL, (void *) &data, 10, iters);
112-
for (i = 1; i <= iters; i *= 2) {
113+
for (i = 1; i <= iters; i = i*1.2 + 1) {
113114
char name[64];
114115
int divisible_iters;
115116
sprintf(name, "schnorrsig_batch_verify_%d", (int) i);
116117

117118
data.n = i;
118119
divisible_iters = iters - (iters % data.n);
119120
run_benchmark(name, bench_schnorrsig_verify_n, NULL, NULL, (void *) &data, 3, divisible_iters);
121+
fflush(stdout);
120122
}
121123

122124
for (i = 0; i < iters; i++) {

0 commit comments

Comments
 (0)