10#include <benchmark/benchmark.h>
15using namespace benchmark;
29 std::string error_message;
30 typename TreeType::AddCompletionCallback completion = [&](
const auto& result) ->
void {
31 success = result.success;
32 error_message = result.message;
36 tree.add_or_update_values(values, completion);
39 throw std::runtime_error(
format(
"Failed to add values: ", error_message));
46 std::string error_message;
48 typename TreeType::AddCompletionCallbackWithWitness completion = [&](
const auto& result) ->
void {
49 success = result.success;
50 error_message = result.message;
54 tree.add_or_update_values(values, completion);
57 throw std::runtime_error(
format(
"Failed to add values with witness: ", error_message));
64 std::string error_message;
66 typename TreeType::AddCompletionCallback completion = [&](
const auto& result) ->
void {
67 success = result.success;
68 error_message = result.message;
72 tree.add_or_update_values_sequentially(values, completion);
75 throw std::runtime_error(
format(
"Failed to add values sequentially: ", error_message));
79template <
typename TreeType>
83 std::string error_message;
85 typename TreeType::AddSequentiallyCompletionCallbackWithWitness completion = [&](
const auto& result) ->
void {
86 success = result.success;
87 error_message = result.message;
91 tree.add_or_update_values_sequentially(values, completion);
94 throw std::runtime_error(
format(
"Failed to add values sequentially with witness: ", error_message));
102 const size_t batch_size = size_t(state.range(0));
107 std::filesystem::create_directories(directory);
108 uint32_t num_threads = 16;
115 const size_t initial_size = 1024 * 16;
117 for (
size_t i = 0; i < initial_size; ++i) {
126 for (
auto _ : state) {
129 for (
size_t i = 0; i < batch_size; ++i) {
132 state.ResumeTiming();
143 const size_t batch_size = size_t(state.range(0));
148 std::filesystem::create_directories(directory);
149 uint32_t num_threads = 1;
156 const size_t initial_size = 1024 * 16;
158 for (
size_t i = 0; i < initial_size; ++i) {
167 for (
auto _ : state) {
170 for (
size_t i = 0; i < batch_size; ++i) {
173 state.ResumeTiming();
182template <
typename TreeType, InsertionStrategy strategy>
185 const size_t batch_size = size_t(state.range(0));
190 std::filesystem::create_directories(directory);
191 uint32_t num_threads = 16;
198 const size_t initial_size = 1024 * 16;
200 for (
size_t i = 0; i < initial_size; ++i) {
209 for (
auto _ : state) {
212 for (
size_t i = 0; i < batch_size; ++i) {
215 state.ResumeTiming();
224template <
typename TreeType, InsertionStrategy strategy>
227 const size_t batch_size = size_t(state.range(0));
232 std::filesystem::create_directories(directory);
233 uint32_t num_threads = 1;
240 const size_t initial_size = 1024 * 16;
242 for (
size_t i = 0; i < initial_size; ++i) {
251 for (
auto _ : state) {
254 for (
size_t i = 0; i < batch_size; ++i) {
257 state.ResumeTiming();
266BENCHMARK(single_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>)
267 ->Unit(benchmark::kMillisecond)
272BENCHMARK(single_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>)
273 ->Unit(benchmark::kMillisecond)
278BENCHMARK(single_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>)
279 ->Unit(benchmark::kMillisecond)
284BENCHMARK(single_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>)
285 ->Unit(benchmark::kMillisecond)
290BENCHMARK(multi_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>)
291 ->Unit(benchmark::kMillisecond)
296BENCHMARK(multi_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>)
297 ->Unit(benchmark::kMillisecond)
302BENCHMARK(multi_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>)
303 ->Unit(benchmark::kMillisecond)
308BENCHMARK(multi_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>)
309 ->Unit(benchmark::kMillisecond)
314BENCHMARK(single_thread_indexed_tree_bench<Poseidon2, BATCH>)
315 ->Unit(benchmark::kMillisecond)
320BENCHMARK(single_thread_indexed_tree_bench<Poseidon2, BATCH>)
321 ->Unit(benchmark::kMillisecond)
326BENCHMARK(single_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>)
327 ->Unit(benchmark::kMillisecond)
332BENCHMARK(single_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>)
333 ->Unit(benchmark::kMillisecond)
338BENCHMARK(multi_thread_indexed_tree_bench<Poseidon2, BATCH>)
339 ->Unit(benchmark::kMillisecond)
344BENCHMARK(multi_thread_indexed_tree_bench<Poseidon2, BATCH>)
345 ->Unit(benchmark::kMillisecond)
350BENCHMARK(multi_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>)
351 ->Unit(benchmark::kMillisecond)
356BENCHMARK(multi_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>)
357 ->Unit(benchmark::kMillisecond)
Native Poseidon2 hash function implementation.
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 ...
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)
ContentAddressedAppendOnlyTree< Store, Poseidon2HashPolicy > TreeType
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)
std::string random_temp_directory()
std::string random_string()
field< Bn254FrParams > fr
BENCHMARK(bench_commit_structured_random_poly< curve::BN254 >) -> Unit(benchmark::kMillisecond)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept