10#include <benchmark/benchmark.h>
15using namespace benchmark;
30 std::string error_message;
31 typename TreeType::AddCompletionCallback completion = [&](
const auto& result) ->
void {
32 success = result.success;
33 error_message = result.message;
37 tree.add_or_update_values(values, completion);
40 throw std::runtime_error(
format(
"Failed to add values: ", error_message));
47 std::string error_message;
49 typename TreeType::AddCompletionCallbackWithWitness completion = [&](
const auto& result) ->
void {
50 success = result.success;
51 error_message = result.message;
55 tree.add_or_update_values(values, completion);
58 throw std::runtime_error(
format(
"Failed to add values with witness: ", error_message));
65 std::string error_message;
67 typename TreeType::AddCompletionCallback completion = [&](
const auto& result) ->
void {
68 success = result.success;
69 error_message = result.message;
73 tree.add_or_update_values_sequentially(values, completion);
76 throw std::runtime_error(
format(
"Failed to add values sequentially: ", error_message));
80template <
typename TreeType>
84 std::string error_message;
86 typename TreeType::AddSequentiallyCompletionCallbackWithWitness completion = [&](
const auto& result) ->
void {
87 success = result.success;
88 error_message = result.message;
92 tree.add_or_update_values_sequentially(values, completion);
95 throw std::runtime_error(
format(
"Failed to add values sequentially with witness: ", error_message));
103 const size_t batch_size = size_t(state.range(0));
108 std::filesystem::create_directories(directory);
109 uint32_t num_threads = 16;
116 const size_t initial_size = 1024 * 16;
118 for (
size_t i = 0; i < initial_size; ++i) {
127 for (
auto _ : state) {
130 for (
size_t i = 0; i < batch_size; ++i) {
133 state.ResumeTiming();
144 const size_t batch_size = size_t(state.range(0));
149 std::filesystem::create_directories(directory);
150 uint32_t num_threads = 1;
157 const size_t initial_size = 1024 * 16;
159 for (
size_t i = 0; i < initial_size; ++i) {
168 for (
auto _ : state) {
171 for (
size_t i = 0; i < batch_size; ++i) {
174 state.ResumeTiming();
183template <
typename TreeType, InsertionStrategy strategy>
186 const size_t batch_size = size_t(state.range(0));
191 std::filesystem::create_directories(directory);
192 uint32_t num_threads = 16;
199 const size_t initial_size = 1024 * 16;
201 for (
size_t i = 0; i < initial_size; ++i) {
210 for (
auto _ : state) {
213 for (
size_t i = 0; i < batch_size; ++i) {
216 state.ResumeTiming();
225template <
typename TreeType, InsertionStrategy strategy>
228 const size_t batch_size = size_t(state.range(0));
233 std::filesystem::create_directories(directory);
234 uint32_t num_threads = 1;
241 const size_t initial_size = 1024 * 16;
243 for (
size_t i = 0; i < initial_size; ++i) {
252 for (
auto _ : state) {
255 for (
size_t i = 0; i < batch_size; ++i) {
258 state.ResumeTiming();
267BENCHMARK(single_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>)
268 ->Unit(benchmark::kMillisecond)
273BENCHMARK(single_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>)
274 ->Unit(benchmark::kMillisecond)
279BENCHMARK(single_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>)
280 ->Unit(benchmark::kMillisecond)
285BENCHMARK(single_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>)
286 ->Unit(benchmark::kMillisecond)
291BENCHMARK(multi_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>)
292 ->Unit(benchmark::kMillisecond)
297BENCHMARK(multi_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>)
298 ->Unit(benchmark::kMillisecond)
303BENCHMARK(multi_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>)
304 ->Unit(benchmark::kMillisecond)
309BENCHMARK(multi_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>)
310 ->Unit(benchmark::kMillisecond)
315BENCHMARK(single_thread_indexed_tree_bench<Poseidon2, BATCH>)
316 ->Unit(benchmark::kMillisecond)
321BENCHMARK(single_thread_indexed_tree_bench<Poseidon2, BATCH>)
322 ->Unit(benchmark::kMillisecond)
327BENCHMARK(single_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>)
328 ->Unit(benchmark::kMillisecond)
333BENCHMARK(single_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>)
334 ->Unit(benchmark::kMillisecond)
339BENCHMARK(multi_thread_indexed_tree_bench<Poseidon2, BATCH>)
340 ->Unit(benchmark::kMillisecond)
345BENCHMARK(multi_thread_indexed_tree_bench<Poseidon2, BATCH>)
346 ->Unit(benchmark::kMillisecond)
351BENCHMARK(multi_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>)
352 ->Unit(benchmark::kMillisecond)
357BENCHMARK(multi_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>)
358 ->Unit(benchmark::kMillisecond)
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 ...
void signal_level(uint32_t level=0)
Signals that the given level has been passed.
void wait_for_level(uint32_t level=0)
Causes the thread to wait until the required level has been signalled.
std::string format(Args... args)
void single_thread_indexed_tree_with_witness_bench(State &state) noexcept
void add_values_sequentially(TreeType &tree, const std::vector< NullifierLeafValue > &values)
void add_values_with_witness(TreeType &tree, const std::vector< NullifierLeafValue > &values)
const size_t MAX_BATCH_SIZE
void multi_thread_indexed_tree_bench(State &state) noexcept
void single_thread_indexed_tree_bench(State &state) noexcept
void add_values_sequentially_with_witness(TreeType &tree, const std::vector< NullifierLeafValue > &values)
void multi_thread_indexed_tree_with_witness_bench(State &state) noexcept
void add_values(TreeType &tree, const std::vector< NullifierLeafValue > &values)
MerkleTree< MemoryStore, PedersenHashPolicy > TreeType
std::string random_temp_directory()
std::string random_string()
field< Bn254FrParams > fr
BENCHMARK(vector_of_evaluations) -> DenseRange(15, 21) ->Unit(kMillisecond) ->Iterations(1)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept