Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
append_only_tree.bench.cpp
Go to the documentation of this file.
13#include <benchmark/benchmark.h>
14#include <cstdint>
15#include <filesystem>
16#include <memory>
17
18using namespace benchmark;
19using namespace bb::crypto::merkle_tree;
20
21namespace {
23
26
27const size_t TREE_DEPTH = 32;
28const size_t MAX_BATCH_SIZE = 64;
29
30template <typename TreeType> void perform_batch_insert(TreeType& tree, const std::vector<fr>& values)
31{
32 Signal signal(1);
33 auto completion = [&](const TypedResponse<AddDataResponse>&) -> void { signal.signal_level(0); };
34
35 tree.add_values(values, completion);
36 signal.wait_for_level(0);
37}
38
39template <typename TreeType> void commit_tree(TreeType& tree)
40{
41 Signal signal(1);
42 auto completion = [&]() -> void { signal.signal_level(0); };
43 tree.commit(completion);
44 signal.wait_for_level(0);
45}
46
47template <typename TreeType> void append_only_tree_bench(State& state) noexcept
48{
49 const size_t batch_size = size_t(state.range(0));
50 const size_t depth = TREE_DEPTH;
51
52 std::string directory = random_temp_directory();
53 std::string name = random_string();
54 std::filesystem::create_directories(directory);
55 uint32_t num_threads = 16;
56
57 LMDBTreeStore::SharedPtr db = std::make_shared<LMDBTreeStore>(directory, name, 1024 * 1024, num_threads);
60 TreeType tree = TreeType(std::move(store), workers);
61
62 for (auto _ : state) {
63 state.PauseTiming();
64 std::vector<fr> values(batch_size);
65 for (size_t i = 0; i < batch_size; ++i) {
66 values[i] = fr(random_engine.get_random_uint256());
67 }
68 state.ResumeTiming();
69 perform_batch_insert(tree, values);
70 }
71
72 std::filesystem::remove_all(directory);
73}
74BENCHMARK(append_only_tree_bench<Poseidon2>)
75 ->Unit(benchmark::kMillisecond)
76 ->RangeMultiplier(2)
77 ->Range(2, MAX_BATCH_SIZE)
78 ->Iterations(1000);
79BENCHMARK(append_only_tree_bench<Poseidon2>)
80 ->Unit(benchmark::kMillisecond)
81 ->RangeMultiplier(2)
82 ->Range(512, 8192)
83 ->Iterations(10);
84
85} // namespace
86
BENCHMARK_MAIN()
Implements a simple append-only merkle tree All methods are asynchronous unless specified as otherwis...
Serves as a key-value node store for merkle trees. Caches all changes in memory before persisting the...
Implements a parallelized batch insertion indexed tree Accepts template argument of the type of store...
std::shared_ptr< LMDBTreeStore > SharedPtr
Used in parallel insertions in the the IndexedTree. Workers signal to other following workes as they ...
Definition signal.hpp:17
void commit_tree(TreeType &tree, bool expected_success=true)
const size_t TREE_DEPTH
const size_t MAX_BATCH_SIZE
MerkleTree< MemoryStore, PedersenHashPolicy > TreeType
std::string random_temp_directory()
Definition fixtures.hpp:42
std::string random_string()
Definition fixtures.hpp:35
field< Bn254FrParams > fr
Definition fr.hpp:174
BENCHMARK(vector_of_evaluations) -> DenseRange(15, 21) ->Unit(kMillisecond) ->Iterations(1)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13