cpp-stat-bench 0.24.0
Benchmark library with statistics for C++.
Loading...
Searching...
No Matches
plot_reporter.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2025 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
21
22#include <cstddef>
23#include <filesystem>
24#include <memory>
25#include <utility>
26
27#include <fmt/format.h>
28
37
38namespace stat_bench {
39namespace reporter {
40
41PlotReporter::PlotReporter(std::string prefix)
42 : prefix_(std::move(prefix)), measurer_name_("") {
43 builtin_plots_.push_back(std::make_shared<plots::SamplesLinePlot>());
44 builtin_plots_.push_back(std::make_shared<plots::CdfLinePlot>());
45 builtin_plots_.push_back(std::make_shared<plots::ViolinPlot>());
46 builtin_plots_.push_back(std::make_shared<plots::BoxPlot>());
47}
48
50 const clock::SystemTimePoint& /*time_stamp*/) {
51 // no operation
52}
53
55 const clock::SystemTimePoint& /*time_stamp*/) {
56 // no operation
57}
58
60 measurer_name_ = name;
61
62 std::string measurer_name_without_space = measurer_name_.str().str();
63 std::size_t pos = 0;
64 while ((pos = measurer_name_without_space.find(' ', pos)) !=
65 std::string::npos) {
66 measurer_name_without_space.erase(pos, 1);
67 }
68
69 measurer_name_for_file_paths_ = util::escape_for_file_name(
70 util::Utf8String(measurer_name_without_space));
71}
72
74 // no operation
75}
76
79 measurements_.clear();
80 group_plots_ = config.plots();
81}
82
84 const auto process_plot = [this, &name](
85 const std::shared_ptr<plots::IPlot>& plot) {
86 const std::string file_path = fmt::format("{}/{}/{}_{}.html", prefix_,
88 measurer_name_for_file_paths_,
89 util::escape_for_file_name(plot->name_for_file()));
90 std::filesystem::create_directories(
91 std::filesystem::path(file_path).parent_path());
92 plot->write(measurer_name_, name, measurements_, file_path);
93 };
94 for (const auto& plot : builtin_plots_) {
95 process_plot(plot);
96 }
97 for (const auto& plot : group_plots_) {
98 process_plot(plot);
99 }
100}
101
103 // no operation
104}
105
107 // no operation
108}
109
111 const measurer::Measurement& measurement) {
112 measurements_.push_back(measurement);
113}
114
116 const BenchmarkCondition& /*cond*/, const std::exception_ptr& /*error*/) {
117 // no operation
118}
119
120} // namespace reporter
121} // namespace stat_bench
Definition of BenchmarkGroupConfig class.
Definition of BenchmarkGroupName class.
Definition of BoxPlot class.
Definition of CdfLinePlot class.
Class of conditions of benchmarks.
Class of information of cases in benchmarks.
Class of names of groups of benchmarks.
auto str() const noexcept -> const util::Utf8String &
Get the string of the name.
Class of configuration of a group of cases in benchmarks.
auto plots() const noexcept -> const std::vector< std::shared_ptr< plots::IPlot > > &
Get the plots in the group.
Class of time points of system clocks.
Class of data of measurements.
Definition measurement.h:42
Class of names of measurers.
auto str() const noexcept -> const util::Utf8String &
Get the string of the name.
void measurer_starts(const measurer::MeasurerName &name) override
Start benchmarks using a measurer.
void group_starts(const BenchmarkGroupName &name, const bench_impl::BenchmarkGroupConfig &config) override
Start a group of benchmarks.
void case_finished(const BenchmarkFullName &case_info) override
Finished a case of a benchmark.
void measurer_finished(const measurer::MeasurerName &name) override
Finished benchmarks using a measurer.
PlotReporter(std::string prefix)
Constructor.
void experiment_starts(const clock::SystemTimePoint &time_stamp) override
Start an experiment.
void case_starts(const BenchmarkFullName &case_info) override
Start a case of a benchmark.
void measurement_succeeded(const measurer::Measurement &measurement) override
Successfully finished a measurement.
void group_finished(const BenchmarkGroupName &name) override
Finished a group of benchmarks.
void measurement_failed(const BenchmarkFullName &case_info, const BenchmarkCondition &cond, const std::exception_ptr &error) override
Failed a measurement.
void experiment_finished(const clock::SystemTimePoint &time_stamp) override
Finished an experiment.
Class of UTF-8 encoded string.
Definition utf8_string.h:35
Declaration of escape_for_file_name function.
Namespace of reporters of results of benchmarks.
auto escape_for_file_name(const Utf8String &input) -> Utf8String
Escape a string for a file name.
Namespace of stat_bench source codes.
STL namespace.
Definition of PlotReporter class.
Definition of SamplesLinePlot class.
Definition of Utf8String class.
Definition of ViolinPlot class.