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
25
26const size_t TREE_DEPTH = 32;
27const size_t MAX_BATCH_SIZE = 64;
28
29template <typename TreeType> void perform_batch_insert(TreeType& tree, const std::vector<fr>& values)
30{
31 Signal signal(1);
32 auto completion = [&](const TypedResponse<AddDataResponse>&) -> void { signal.signal_level(0); };
33
34 tree.add_values(values, completion);
35 signal.wait_for_level(0);
36}
37
38template <typename TreeType> void commit_tree(TreeType& tree)
39{
40 Signal signal(1);
41 auto completion = [&]() -> void { signal.signal_level(0); };
42 tree.commit(completion);
43 signal.wait_for_level(0);
44}
45
46template <typename TreeType> void append_only_tree_bench(State& state) noexcept
47{
48 const size_t batch_size = size_t(state.range(0));
49 const size_t depth = TREE_DEPTH;
50
51 std::string directory = random_temp_directory();
52 std::string name = random_string();
53 std::filesystem::create_directories(directory);
54 uint32_t num_threads = 16;
55
56 LMDBTreeStore::SharedPtr db = std::make_shared<LMDBTreeStore>(directory, name, 1024 * 1024, num_threads);
59 TreeType tree = TreeType(std::move(store), workers);
60
61 for (auto _ : state) {
62 state.PauseTiming();
63 std::vector<fr> values(batch_size);
64 for (size_t i = 0; i < batch_size; ++i) {
65 values[i] = fr(random_engine.get_random_uint256());
66 }
67 state.ResumeTiming();
68 perform_batch_insert(tree, values);
69 }
70
71 std::filesystem::remove_all(directory);
72}
73BENCHMARK(append_only_tree_bench<Poseidon2>)
74 ->Unit(benchmark::kMillisecond)
75 ->RangeMultiplier(2)
76 ->Range(2, MAX_BATCH_SIZE)
77 ->Iterations(1000);
78BENCHMARK(append_only_tree_bench<Poseidon2>)
79 ->Unit(benchmark::kMillisecond)
80 ->RangeMultiplier(2)
81 ->Range(512, 8192)
82 ->Iterations(10);
83
84} // namespace
85
BENCHMARK_MAIN()
Native Poseidon2 hash function implementation.
Definition poseidon2.hpp:22
Implements a simple append-only merkle tree All methods are asynchronous unless specified as otherwis...
void commit(const CommitCallback &on_completion)
Commit the tree to the backing store.
virtual void add_values(const std::vector< fr > &values, const AppendCompletionCallback &on_completion)
Adds the given set of values to the end of the tree.
Serves as a key-value node store for merkle trees. Caches all changes in memory before persisting the...
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
ContentAddressedAppendOnlyTree< Store, Poseidon2HashPolicy > TreeType
void commit_tree(TreeType &tree, bool expected_success=true)
const size_t TREE_DEPTH
const size_t MAX_BATCH_SIZE
std::string random_temp_directory()
Definition fixtures.hpp:37
std::string random_string()
Definition fixtures.hpp:30
field< Bn254FrParams > fr
Definition fr.hpp:155
BENCHMARK(bench_commit_structured_random_poly< curve::BN254 >) -> Unit(benchmark::kMillisecond)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13