Skip to content

Commit b34bf30

Browse files
committed
Add Poly1305 bench
1 parent 03be7f4 commit b34bf30

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/Makefile.bench.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ bench_bench_bitcoin_SOURCES = \
3030
bench/base58.cpp \
3131
bench/bech32.cpp \
3232
bench/lockedpool.cpp \
33+
bench/poly1305.cpp \
3334
bench/prevector.cpp
3435

3536
nodist_bench_bench_bitcoin_SOURCES = $(GENERATED_BENCH_FILES)

src/bench/poly1305.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) 2019 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <iostream>
6+
7+
#include <bench/bench.h>
8+
#include <crypto/poly1305.h>
9+
10+
/* Number of bytes to process per iteration */
11+
static constexpr uint64_t BUFFER_SIZE_TINY = 64;
12+
static constexpr uint64_t BUFFER_SIZE_SMALL = 256;
13+
static constexpr uint64_t BUFFER_SIZE_LARGE = 1024*1024;
14+
15+
static void POLY1305(benchmark::State& state, size_t buffersize)
16+
{
17+
std::vector<unsigned char> tag(POLY1305_TAGLEN, 0);
18+
std::vector<unsigned char> key(POLY1305_KEYLEN, 0);
19+
std::vector<unsigned char> in(buffersize, 0);
20+
while (state.KeepRunning())
21+
poly1305_auth(tag.data(), in.data(), in.size(), key.data());
22+
}
23+
24+
static void POLY1305_64BYTES(benchmark::State& state)
25+
{
26+
POLY1305(state, BUFFER_SIZE_TINY);
27+
}
28+
29+
static void POLY1305_256BYTES(benchmark::State& state)
30+
{
31+
POLY1305(state, BUFFER_SIZE_SMALL);
32+
}
33+
34+
static void POLY1305_1MB(benchmark::State& state)
35+
{
36+
POLY1305(state, BUFFER_SIZE_LARGE);
37+
}
38+
39+
BENCHMARK(POLY1305_64BYTES, 500000);
40+
BENCHMARK(POLY1305_256BYTES, 250000);
41+
BENCHMARK(POLY1305_1MB, 340);

0 commit comments

Comments
 (0)