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)), group_name_(""), measurement_type_("") {
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
61 group_name_ = name;
62 group_plots_ = config.plots();
63}
64
66 // no operation
67}
68
70 const measurer::MeasurementType& type) {
71 measurement_type_ = type;
72
73 std::string measurement_type_without_space = measurement_type_.str().str();
74 std::size_t pos = 0;
75 while ((pos = measurement_type_without_space.find(' ', pos)) !=
76 std::string::npos) {
77 measurement_type_without_space.erase(pos, 1);
78 }
79
80 measurement_type_for_file_paths_ = util::escape_for_file_name(
81 util::Utf8String(measurement_type_without_space));
82}
83
85 const measurer::MeasurementType& /*type*/) {
86 const auto process_plot = [this](
87 const std::shared_ptr<plots::IPlot>& plot) {
88 const std::string file_path = fmt::format("{}/{}/{}_{}.html", prefix_,
89 util::escape_for_file_name(group_name_.str()),
90 measurement_type_for_file_paths_,
91 util::escape_for_file_name(plot->name_for_file()));
92 std::filesystem::create_directories(
93 std::filesystem::path(file_path).parent_path());
94 plot->write(measurement_type_, group_name_, measurements_, file_path);
95 };
96 for (const auto& plot : builtin_plots_) {
97 process_plot(plot);
98 }
99 for (const auto& plot : group_plots_) {
100 process_plot(plot);
101 }
102
103 measurements_.clear();
104}
105
107 // no operation
108}
109
111 // no operation
112}
113
115 const measurer::Measurement& measurement) {
116 measurements_.push_back(measurement);
117}
118
120 const BenchmarkCondition& /*cond*/, const std::exception_ptr& /*error*/) {
121 // no operation
122}
123
124} // namespace reporter
125} // 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.
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 names of measurement types.
auto str() const noexcept -> const util::Utf8String &
Get the string of the name.
Class of data of measurements.
Definition measurement.h:42
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.
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 measurement_type_starts(const measurer::MeasurementType &type) final
Start a measurement with a type.
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.
void measurement_type_finished(const measurer::MeasurementType &type) final
Finished a measurement with a type.
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.