Add Hash Padding Microbenchmarks
This commit is contained in:
parent
ba348dbc51
commit
5495fa5850
2 changed files with 48 additions and 0 deletions
|
@ -29,6 +29,7 @@ bench_bench_bitcoin_SOURCES = \
|
||||||
bench/crypto_hash.cpp \
|
bench/crypto_hash.cpp \
|
||||||
bench/ccoins_caching.cpp \
|
bench/ccoins_caching.cpp \
|
||||||
bench/gcs_filter.cpp \
|
bench/gcs_filter.cpp \
|
||||||
|
bench/hashpadding.cpp \
|
||||||
bench/merkle_root.cpp \
|
bench/merkle_root.cpp \
|
||||||
bench/mempool_eviction.cpp \
|
bench/mempool_eviction.cpp \
|
||||||
bench/mempool_stress.cpp \
|
bench/mempool_stress.cpp \
|
||||||
|
|
47
src/bench/hashpadding.cpp
Normal file
47
src/bench/hashpadding.cpp
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
// Copyright (c) 2015-2018 The Bitcoin Core developers
|
||||||
|
// Distributed under the MIT software license, see the accompanying
|
||||||
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#include <bench/bench.h>
|
||||||
|
#include <hash.h>
|
||||||
|
#include <random.h>
|
||||||
|
#include <uint256.h>
|
||||||
|
|
||||||
|
|
||||||
|
static void PrePadded(benchmark::State& state)
|
||||||
|
{
|
||||||
|
|
||||||
|
CSHA256 hasher;
|
||||||
|
|
||||||
|
// Setup the salted hasher
|
||||||
|
uint256 nonce = GetRandHash();
|
||||||
|
hasher.Write(nonce.begin(), 32);
|
||||||
|
hasher.Write(nonce.begin(), 32);
|
||||||
|
uint256 data = GetRandHash();
|
||||||
|
while (state.KeepRunning()) {
|
||||||
|
unsigned char out[32];
|
||||||
|
CSHA256 h = hasher;
|
||||||
|
h.Write(data.begin(), 32);
|
||||||
|
h.Finalize(out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BENCHMARK(PrePadded, 10000);
|
||||||
|
|
||||||
|
static void RegularPadded(benchmark::State& state)
|
||||||
|
{
|
||||||
|
CSHA256 hasher;
|
||||||
|
|
||||||
|
// Setup the salted hasher
|
||||||
|
uint256 nonce = GetRandHash();
|
||||||
|
uint256 data = GetRandHash();
|
||||||
|
while (state.KeepRunning()) {
|
||||||
|
unsigned char out[32];
|
||||||
|
CSHA256 h = hasher;
|
||||||
|
h.Write(nonce.begin(), 32);
|
||||||
|
h.Write(data.begin(), 32);
|
||||||
|
h.Finalize(out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BENCHMARK(RegularPadded, 10000);
|
Loading…
Reference in a new issue