17 std::vector<uint256> hashes{};
19 for (
auto& item : hashes) {
23 constexpr uint256 expected_root{
"d8d4dfd014a533bc3941b8663fa6e7f3a8707af124f713164d75b0c3179ecb08"};
24 for (
bool mutate : {
false,
true}) {
25 bench.
name(mutate ?
"MerkleRootWithMutation" :
"MerkleRoot").
batch(hashes.size()).
unit(
"leaf").
run([&] {
26 std::vector<uint256> leaves;
27 leaves.reserve((hashes.size() + 1) & ~1ULL);
28 for (
size_t s = 0;
s < hashes.size();
s++) {
29 leaves.push_back(hashes[
s]);
34 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(const CTxIn &txin :tx.vin)