forked from nanocurrency/nano-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f55b903
commit 04271be
Showing
3 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <benchmark/benchmark.h> | ||
|
||
static void BM_StringCreation (benchmark::State & state) | ||
{ | ||
for (auto _ : state) | ||
std::string empty_string; | ||
} | ||
// Register the function as a benchmark | ||
BENCHMARK (BM_StringCreation); | ||
|
||
// Define another benchmark | ||
static void BM_StringCopy (benchmark::State & state) | ||
{ | ||
std::string x = "hello"; | ||
for (auto _ : state) | ||
std::string copy (x); | ||
} | ||
BENCHMARK (BM_StringCopy); | ||
|
||
BENCHMARK_MAIN (); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <nano/lib/stats.hpp> | ||
|
||
#include <random> | ||
|
||
#include <benchmark/benchmark.h> | ||
|
||
static void benchmark_stats_inc_single (benchmark::State & state) | ||
{ | ||
nano::stats stats; | ||
|
||
for (auto _ : state) | ||
{ | ||
stats.inc (nano::stat::type::ledger, nano::stat::detail::open); | ||
} | ||
} | ||
|
||
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 ({ 64, 64 }); | ||
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 ({ 64, 64 })->Threads (16); |