Bitcoin Core  29.1.0
P2P Digital Currency
merkle_root.cpp
Go to the documentation of this file.
1 // Copyright (c) 2016-2022 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 <consensus/merkle.h>
7 #include <random.h>
8 #include <uint256.h>
9 
10 #include <vector>
11 
12 static void MerkleRoot(benchmark::Bench& bench)
13 {
14  FastRandomContext rng(true);
15  std::vector<uint256> leaves;
16  leaves.resize(9001);
17  for (auto& item : leaves) {
18  item = rng.rand256();
19  }
20  bench.batch(leaves.size()).unit("leaf").run([&] {
21  bool mutation = false;
22  uint256 hash = ComputeMerkleRoot(std::vector<uint256>(leaves), &mutation);
23  leaves[mutation] = hash;
24  });
25 }
26 
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1234
Fast randomness source.
Definition: random.h:376
256-bit opaque blob.
Definition: uint256.h:201
uint256 ComputeMerkleRoot(std::vector< uint256 > hashes, bool *mutated)
Definition: merkle.cpp:46
uint256 rand256() noexcept
generate a random uint256.
Definition: random.h:308
static void MerkleRoot(benchmark::Bench &bench)
Definition: merkle_root.cpp:12
Main entry point to nanobench&#39;s benchmarking facility.
Definition: nanobench.h:627
Bench & batch(T b) noexcept
Sets the batch size.
Definition: nanobench.h:1258
BENCHMARK(MerkleRoot, benchmark::PriorityLevel::HIGH)