Skip to content

Commit 2dfe275

Browse files
committed
Add ChaCha20 bench
1 parent 2bc2b8b commit 2dfe275

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/Makefile.bench.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ bench_bench_bitcoin_SOURCES = \
2121
bench/duplicate_inputs.cpp \
2222
bench/examples.cpp \
2323
bench/rollingbloom.cpp \
24+
bench/chacha20.cpp \
2425
bench/crypto_hash.cpp \
2526
bench/ccoins_caching.cpp \
2627
bench/gcs_filter.cpp \

src/bench/chacha20.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 <hash.h>
9+
#include <crypto/chacha20.h>
10+
11+
/* Number of bytes to process per iteration */
12+
static const uint64_t BUFFER_SIZE_TINY = 64;
13+
static const uint64_t BUFFER_SIZE_SMALL = 256;
14+
static const uint64_t BUFFER_SIZE_LARGE = 1024*1024;
15+
16+
static void CHACHA20(benchmark::State& state, size_t buffersize)
17+
{
18+
std::vector<uint8_t> key(32,0);
19+
ChaCha20 ctx(key.data(), key.size());
20+
ctx.SetIV(0);
21+
ctx.Seek(0);
22+
std::vector<uint8_t> in(buffersize,0);
23+
std::vector<uint8_t> out(buffersize,0);
24+
while (state.KeepRunning()) {
25+
ctx.Crypt(in.data(), out.data(), in.size());
26+
}
27+
}
28+
29+
static void CHACHA20_64BYTES(benchmark::State& state)
30+
{
31+
CHACHA20(state, BUFFER_SIZE_TINY);
32+
}
33+
34+
static void CHACHA20_256BYTES(benchmark::State& state)
35+
{
36+
CHACHA20(state, BUFFER_SIZE_SMALL);
37+
}
38+
39+
static void CHACHA20_1MB(benchmark::State& state)
40+
{
41+
CHACHA20(state, BUFFER_SIZE_LARGE);
42+
}
43+
44+
BENCHMARK(CHACHA20_64BYTES, 500000);
45+
BENCHMARK(CHACHA20_256BYTES, 250000);
46+
BENCHMARK(CHACHA20_1MB, 340);

0 commit comments

Comments
 (0)