Skip to content

Commit

Permalink
Benchmark Merkle root computation
Browse files Browse the repository at this point in the history
Cherry-picked from: 0df0178
  • Loading branch information
sipa authored and xanimo committed Apr 25, 2024
1 parent f7892fb commit 8a3a644
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Makefile.bench.include
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ bench_bench_dogecoin_SOURCES = \
bench/chacha20.cpp \
bench/crypto_hash.cpp \
bench/ccoins_caching.cpp \
bench/merkle_root.cpp \
bench/mempool_eviction.cpp \
bench/base58.cpp \
bench/lockedpool.cpp \
Expand Down
26 changes: 26 additions & 0 deletions src/bench/merkle_root.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2016 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.h"

#include "uint256.h"
#include "random.h"
#include "consensus/merkle.h"

static void MerkleRoot(benchmark::State& state)
{
FastRandomContext rng(true);
std::vector<uint256> leaves;
leaves.resize(9001);
for (auto& item : leaves) {
item = rng.rand256();
}
while (state.KeepRunning()) {
bool mutation = false;
uint256 hash = ComputeMerkleRoot(leaves, &mutation);
leaves[mutation] = hash;
}
}

BENCHMARK(MerkleRoot);

0 comments on commit 8a3a644

Please sign in to comment.