Skip to content

Commit 5495fa5

Browse files
committed
Add Hash Padding Microbenchmarks
1 parent ba348db commit 5495fa5

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/Makefile.bench.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ bench_bench_bitcoin_SOURCES = \
2929
bench/crypto_hash.cpp \
3030
bench/ccoins_caching.cpp \
3131
bench/gcs_filter.cpp \
32+
bench/hashpadding.cpp \
3233
bench/merkle_root.cpp \
3334
bench/mempool_eviction.cpp \
3435
bench/mempool_stress.cpp \

src/bench/hashpadding.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) 2015-2018 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 <bench/bench.h>
6+
#include <hash.h>
7+
#include <random.h>
8+
#include <uint256.h>
9+
10+
11+
static void PrePadded(benchmark::State& state)
12+
{
13+
14+
CSHA256 hasher;
15+
16+
// Setup the salted hasher
17+
uint256 nonce = GetRandHash();
18+
hasher.Write(nonce.begin(), 32);
19+
hasher.Write(nonce.begin(), 32);
20+
uint256 data = GetRandHash();
21+
while (state.KeepRunning()) {
22+
unsigned char out[32];
23+
CSHA256 h = hasher;
24+
h.Write(data.begin(), 32);
25+
h.Finalize(out);
26+
}
27+
}
28+
29+
BENCHMARK(PrePadded, 10000);
30+
31+
static void RegularPadded(benchmark::State& state)
32+
{
33+
CSHA256 hasher;
34+
35+
// Setup the salted hasher
36+
uint256 nonce = GetRandHash();
37+
uint256 data = GetRandHash();
38+
while (state.KeepRunning()) {
39+
unsigned char out[32];
40+
CSHA256 h = hasher;
41+
h.Write(nonce.begin(), 32);
42+
h.Write(data.begin(), 32);
43+
h.Finalize(out);
44+
}
45+
}
46+
47+
BENCHMARK(RegularPadded, 10000);

0 commit comments

Comments
 (0)