Changeset View
Changeset View
Standalone View
Standalone View
src/bench/bench.cpp
Show All 10 Lines | |||||
#include <algorithm> | #include <algorithm> | ||||
#include <cassert> | #include <cassert> | ||||
#include <iomanip> | #include <iomanip> | ||||
#include <iostream> | #include <iostream> | ||||
#include <numeric> | #include <numeric> | ||||
#include <regex> | #include <regex> | ||||
const RegTestingSetup *g_testing_setup = nullptr; | |||||
void benchmark::ConsolePrinter::header() { | void benchmark::ConsolePrinter::header() { | ||||
std::cout << "# Benchmark, evals, iterations, total, min, max, median" | std::cout << "# Benchmark, evals, iterations, total, min, max, median" | ||||
<< std::endl; | << std::endl; | ||||
} | } | ||||
void benchmark::ConsolePrinter::result(const State &state) { | void benchmark::ConsolePrinter::result(const State &state) { | ||||
auto results = state.m_elapsed_results; | auto results = state.m_elapsed_results; | ||||
std::sort(results.begin(), results.end()); | std::sort(results.begin(), results.end()); | ||||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | |||||
#endif | #endif | ||||
std::regex reFilter(filter); | std::regex reFilter(filter); | ||||
std::smatch baseMatch; | std::smatch baseMatch; | ||||
printer.header(); | printer.header(); | ||||
for (const auto &p : benchmarks()) { | for (const auto &p : benchmarks()) { | ||||
RegTestingSetup test{}; | |||||
assert(g_testing_setup == nullptr); | |||||
g_testing_setup = &test; | |||||
assert(::ChainActive().Height() == 0); | |||||
if (!std::regex_match(p.first, baseMatch, reFilter)) { | if (!std::regex_match(p.first, baseMatch, reFilter)) { | ||||
g_testing_setup = nullptr; | |||||
continue; | continue; | ||||
} | } | ||||
uint64_t num_iters = | uint64_t num_iters = | ||||
static_cast<uint64_t>(p.second.num_iters_for_one_second * scaling); | static_cast<uint64_t>(p.second.num_iters_for_one_second * scaling); | ||||
if (0 == num_iters) { | if (0 == num_iters) { | ||||
num_iters = 1; | num_iters = 1; | ||||
} | } | ||||
State state(p.first, num_evals, num_iters, printer); | State state(p.first, num_evals, num_iters, printer); | ||||
if (!is_list_only) { | if (!is_list_only) { | ||||
p.second.func(state); | p.second.func(state); | ||||
} | } | ||||
printer.result(state); | printer.result(state); | ||||
g_testing_setup = nullptr; | |||||
} | } | ||||
printer.footer(); | printer.footer(); | ||||
} | } | ||||
bool benchmark::State::UpdateTimer(const benchmark::time_point current_time) { | bool benchmark::State::UpdateTimer(const benchmark::time_point current_time) { | ||||
if (m_start_time != time_point()) { | if (m_start_time != time_point()) { | ||||
std::chrono::duration<double> diff = current_time - m_start_time; | std::chrono::duration<double> diff = current_time - m_start_time; | ||||
Show All 10 Lines |