11#include <initializer_list>
19 std::vector<uint256> hashes{};
21 for (
auto& item : hashes) {
25 constexpr uint256 expected_root{
"d8d4dfd014a533bc3941b8663fa6e7f3a8707af124f713164d75b0c3179ecb08"};
26 for (
bool mutate : {
false,
true}) {
27 bench.
name(mutate ?
"MerkleRootWithMutation" :
"MerkleRoot").
batch(hashes.size()).
unit(
"leaf").
run([&] {
28 std::vector<uint256> leaves;
29 leaves.reserve((hashes.size() + 1) & ~1ULL);
30 for (
const auto& hash : hashes) {
31 leaves.push_back(hash);
36 assert(root == expected_root);
uint256 rand256() noexcept
generate a random uint256.
Main entry point to nanobench's benchmarking facility.
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
ANKERL_NANOBENCH(NODISCARD) std Bench & name(char const *benchmarkName)
Gets the title of the benchmark.
Bench & batch(T b) noexcept
Sets the batch size.
Bench & unit(char const *unit)
Sets the operation unit.
uint256 ComputeMerkleRoot(std::vector< uint256 > hashes, bool *mutated)
static void MerkleRoot(benchmark::Bench &bench)
for(size_t start{0};start< num_entries;start+=SEED_BATCH_SIZE)