merkle_root.cpp raw
1 // Copyright (c) 2016-2022 The Limenka 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
27 BENCHMARK(MerkleRoot, benchmark::PriorityLevel::HIGH);
28