Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Mar 23, 2024
1 parent 05b7d0d commit 8a3b930
Showing 1 changed file with 56 additions and 2 deletions.
58 changes: 56 additions & 2 deletions nano/benchmarks/stats.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include <nano/lib/stats.hpp>

#include <random>

#include <benchmark/benchmark.h>

static void benchmark_stats_inc (benchmark::State & state)
static void benchmark_stats_inc_single (benchmark::State & state)
{
nano::stats stats;

Expand All @@ -11,4 +13,56 @@ static void benchmark_stats_inc (benchmark::State & state)
stats.inc (nano::stat::type::ledger, nano::stat::detail::open);
}
}
BENCHMARK (benchmark_stats_inc);

BENCHMARK (benchmark_stats_inc_single);
BENCHMARK (benchmark_stats_inc_single)->Threads (16);

static void benchmark_stats_inc_multiple (benchmark::State & state)
{
nano::stats stats;

for (auto _ : state)
{
stats.inc (nano::stat::type::ledger, nano::stat::detail::open);
stats.inc (nano::stat::type::active, nano::stat::detail::activate);
stats.inc (nano::stat::type::active, nano::stat::detail::block);
stats.inc (nano::stat::type::aggregator, nano::stat::detail::block);
stats.inc (nano::stat::type::aggregator, nano::stat::detail::cleanup);
stats.inc (nano::stat::type::aggregator, nano::stat::detail::already_confirmed);
stats.inc (nano::stat::type::backlog, nano::stat::detail::insert);
}
}

BENCHMARK (benchmark_stats_inc_multiple);
BENCHMARK (benchmark_stats_inc_multiple)->Threads (16);

static void benchmark_stats_inc_random (benchmark::State & state)
{
nano::stats stats;

auto random_subset = [] (auto elements, size_t count) -> std::vector<typename decltype (elements)::value_type> {
std::shuffle (elements.begin (), elements.end (), std::mt19937 (std::random_device () ()));
return { elements.begin (), elements.begin () + std::min (count, elements.size ()) };
};

auto stat_types = random_subset (nano::stat::all_types (), state.range (0));
auto stat_details = random_subset (nano::stat::all_details (), state.range (1));

size_t type_index = 0;
size_t detail_index = 0;

for (auto _ : state)
{
stats.inc (stat_types[type_index], stat_details[detail_index]);

type_index = (type_index + 1) % stat_types.size ();
detail_index = (detail_index + 1) % stat_details.size ();
}
}

BENCHMARK (benchmark_stats_inc_random)->Args ({ 8, 8 });
BENCHMARK (benchmark_stats_inc_random)->Args ({ 16, 16 });
BENCHMARK (benchmark_stats_inc_random)->Args ({ 32, 32 });
BENCHMARK (benchmark_stats_inc_random)->Args ({ 8, 8 })->Threads (16);
BENCHMARK (benchmark_stats_inc_random)->Args ({ 16, 16 })->Threads (16);
BENCHMARK (benchmark_stats_inc_random)->Args ({ 32, 32 })->Threads (16);

0 comments on commit 8a3b930

Please sign in to comment.