19 std::cout <<
"# Benchmark, evals, iterations, total, min, max, median" << std::endl;
25 std::sort(results.begin(), results.end());
27 double total = state.
m_num_iters * std::accumulate(results.begin(), results.end(), 0.0);
33 if (!results.empty()) {
34 front = results.front();
35 back = results.back();
37 size_t mid = results.size() / 2;
38 median = results[mid];
39 if (0 == results.size() % 2) {
40 median = (results[mid] + results[mid + 1]) / 2;
44 std::cout << std::setprecision(6);
45 std::cout << state.
m_name <<
", " << state.
m_num_evals <<
", " << state.
m_num_iters <<
", " << total <<
", " << front <<
", " << back <<
", " << median << std::endl;
50 : m_plotly_url(plotly_url), m_width(width), m_height(height)
56 std::cout <<
"<html><head>"
57 <<
"<script src=\"" << m_plotly_url <<
"\"></script>"
58 <<
"</head><body><div id=\"myDiv\" style=\"width:" << m_width <<
"px; height:" << m_height <<
"px\"></div>"
59 <<
"<script> var data = ["
65 std::cout <<
"{ " << std::endl
66 <<
" name: '" << state.
m_name <<
"', " << std::endl
71 std::cout <<
prefix << std::setprecision(6) << e;
74 std::cout <<
"]," << std::endl
75 <<
" boxpoints: 'all', jitter: 0.3, pointpos: 0, type: 'box',"
82 std::cout <<
"]; var layout = { showlegend: false, yaxis: { rangemode: 'tozero', autorange: true } };"
83 <<
"Plotly.newPlot('myDiv', data, layout);"
84 <<
"</script></body></html>";
90 static std::map<std::string, Bench> benchmarks_map;
91 return benchmarks_map;
96 benchmarks().insert(std::make_pair(
name,
Bench{func, num_iters_for_one_second}));
102 if (!std::ratio_less_equal<benchmark::clock::period, std::micro>::value) {
103 std::cerr <<
"WARNING: Clock precision is worse than microsecond - benchmarks may be less accurate!\n";
106 std::regex reFilter(filter);
107 std::smatch baseMatch;
111 for (
const auto& p : benchmarks()) {
112 if (!std::regex_match(p.first, baseMatch, reFilter)) {
116 uint64_t num_iters =
static_cast<uint64_t
>(p.second.num_iters_for_one_second * scaling);
117 if (0 == num_iters) {
120 State state(p.first, num_evals, num_iters, printer);
122 p.second.func(state);
135 std::chrono::duration<double> diff = current_time - m_start_time;
136 m_elapsed_results.push_back(diff.count() / m_num_iters);
138 if (m_elapsed_results.size() == m_num_evals) {
143 m_num_iters_left = m_num_iters - 1;
static BenchmarkMap & benchmarks()
BenchRunner(std::string name, BenchFunction func, uint64_t num_iters_for_one_second)
std::map< std::string, Bench > BenchmarkMap
static void RunAll(Printer &printer, uint64_t num_evals, double scaling, const std::string &filter, bool is_list_only)
void result(const State &state)
PlotlyPrinter(std::string plotly_url, int64_t width, int64_t height)
void result(const State &state)
virtual void result(const State &state)=0
const uint64_t m_num_evals
std::vector< double > m_elapsed_results
bool UpdateTimer(time_point finish_time)
const uint64_t m_num_iters
std::function< void(State &)> BenchFunction
clock::time_point time_point