Changeset View
Changeset View
Standalone View
Standalone View
src/bench/bench.cpp
// Copyright (c) 2015-2016 The Bitcoin Core developers | // Copyright (c) 2015-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <bench/bench.h> | #include <bench/bench.h> | ||||
#include <bench/perf.h> | |||||
#include <algorithm> | #include <algorithm> | ||||
#include <cassert> | #include <cassert> | ||||
#include <iomanip> | #include <iomanip> | ||||
#include <iostream> | #include <iostream> | ||||
#include <numeric> | #include <numeric> | ||||
#include <regex> | #include <regex> | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | benchmark::BenchRunner::BenchRunner(std::string name, | ||||
uint64_t num_iters_for_one_second) { | uint64_t num_iters_for_one_second) { | ||||
benchmarks().insert( | benchmarks().insert( | ||||
std::make_pair(name, Bench{func, num_iters_for_one_second})); | std::make_pair(name, Bench{func, num_iters_for_one_second})); | ||||
} | } | ||||
void benchmark::BenchRunner::RunAll(Printer &printer, uint64_t num_evals, | void benchmark::BenchRunner::RunAll(Printer &printer, uint64_t num_evals, | ||||
double scaling, const std::string &filter, | double scaling, const std::string &filter, | ||||
bool is_list_only) { | bool is_list_only) { | ||||
perf_init(); | |||||
if (!std::ratio_less_equal<benchmark::clock::period, std::micro>::value) { | if (!std::ratio_less_equal<benchmark::clock::period, std::micro>::value) { | ||||
std::cerr << "WARNING: Clock precision is worse than microsecond - " | std::cerr << "WARNING: Clock precision is worse than microsecond - " | ||||
"benchmarks may be less accurate!\n"; | "benchmarks may be less accurate!\n"; | ||||
} | } | ||||
std::regex reFilter(filter); | std::regex reFilter(filter); | ||||
std::smatch baseMatch; | std::smatch baseMatch; | ||||
Show All 12 Lines | for (const auto &p : benchmarks()) { | ||||
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); | ||||
} | } | ||||
printer.footer(); | printer.footer(); | ||||
perf_fini(); | |||||
} | } | ||||
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; | ||||
m_elapsed_results.push_back(diff.count() / m_num_iters); | m_elapsed_results.push_back(diff.count() / m_num_iters); | ||||
if (m_elapsed_results.size() == m_num_evals) { | if (m_elapsed_results.size() == m_num_evals) { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
m_num_iters_left = m_num_iters - 1; | m_num_iters_left = m_num_iters - 1; | ||||
return true; | return true; | ||||
} | } |