Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
merkle_tree.bench.cpp
Go to the documentation of this file.
5#include <benchmark/benchmark.h>
6
7using namespace benchmark;
8using namespace bb;
9using namespace bb::crypto::merkle_tree;
10
12
13namespace {
15} // namespace
16
17constexpr size_t DEPTH = 256;
18constexpr size_t MAX = 4096;
19
20static std::vector<fr> VALUES = []() {
21 std::vector<fr> values(MAX);
22 for (size_t i = 0; i < MAX; ++i) {
23 values[i] = fr(i);
24 }
25 return values;
26}();
27
28void hash(State& state) noexcept
29{
30 for (auto _ : state) {
31 hash_pair_native({ 0, 0, 0, 0 }, { 1, 1, 1, 1 });
32 }
33}
34BENCHMARK(hash)->MinTime(5);
35
36void update_first_element(State& state) noexcept
37{
38 MemoryStore store;
39 TreeType db(store, DEPTH);
40
41 for (auto _ : state) {
42 db.update_element(0, VALUES[1]);
43 }
44}
45BENCHMARK(update_first_element)->Unit(benchmark::kMillisecond);
46
47void update_elements(State& state) noexcept
48{
49 for (auto _ : state) {
50 state.PauseTiming();
51 MemoryStore store;
52 TreeType db(store, DEPTH);
53 state.ResumeTiming();
54 for (size_t i = 0; i < (size_t)state.range(0); ++i) {
55 db.update_element(i, VALUES[i]);
56 }
57 }
58}
59BENCHMARK(update_elements)->Unit(benchmark::kMillisecond)->RangeMultiplier(2)->Range(256, MAX);
60
61void update_random_elements(State& state) noexcept
62{
63 for (auto _ : state) {
64 state.PauseTiming();
65 MemoryStore store;
66 TreeType db(store, DEPTH);
67 for (size_t i = 0; i < (size_t)state.range(0); i++) {
68 state.PauseTiming();
69 auto index = TreeType::index_t(engine.get_random_uint256());
70 state.ResumeTiming();
71 db.update_element(index, VALUES[i]);
72 }
73 }
74}
75BENCHMARK(update_random_elements)->Unit(benchmark::kMillisecond)->Range(100, 100)->Iterations(1);
76
fr update_element(index_t index, fr const &value)
void update_random_elements(State &state) noexcept
BENCHMARK_MAIN()
constexpr size_t DEPTH
constexpr size_t MAX
void update_elements(State &state) noexcept
void hash(State &state) noexcept
BENCHMARK(hash) -> MinTime(5)
void update_first_element(State &state) noexcept
bb::fr hash_pair_native(bb::fr const &lhs, bb::fr const &rhs)
Definition hash.hpp:40
RNG & get_debug_randomness(bool reset, std::uint_fast64_t seed)
Definition engine.cpp:190
Entry point for Barretenberg command-line interface.
field< Bn254FrParams > fr
Definition fr.hpp:174