cpp-stat-bench 0.24.0
Benchmark library with statistics for C++.
Loading...
Searching...
No Matches
benchmark_group_register.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 <cstdlib>
23#include <exception>
24#include <iostream>
25#include <memory>
26#include <string>
27
39
40namespace stat_bench {
41namespace bench_impl {
42
44 const BenchmarkGroupName& name) noexcept {
45 try {
46 group_ = &BenchmarkCaseRegistry::instance().add_or_get_group(name);
47 } catch (const std::exception& e) {
48 std::cerr << "Failed to append a benchmark group: " << e.what()
49 << std::endl; // NOLINT(performance-avoid-endl)
50 std::exit(1); // NOLINT(concurrency-mt-unsafe)
51 }
52}
53
55 util::StringView parameter_name, PlotOptions options) noexcept
57 try {
58 group_->config().add_plot(
59 std::make_shared<plots::ParameterToTimeLinePlot>(
61 std::string(parameter_name.data(), parameter_name.size())),
62 options));
63 return *this;
64 } catch (const std::exception& e) {
65 std::cerr << "Failed to append a plot to a benchmark group: "
66 << e.what() << std::endl; // NOLINT(performance-avoid-endl)
67 std::exit(1); // NOLINT(concurrency-mt-unsafe)
68 }
69}
70
72 util::StringView parameter_name) noexcept -> BenchmarkGroupRegister& {
74 parameter_name, PlotOptions().log_parameter(true));
75}
76
78 util::StringView parameter_name, PlotOptions options) noexcept
80 try {
81 group_->config().add_plot(
82 std::make_shared<plots::ParameterToTimeViolinPlot>(
84 std::string(parameter_name.data(), parameter_name.size())),
85 options));
86 return *this;
87 } catch (const std::exception& e) {
88 std::cerr << "Failed to append a plot to a benchmark group: "
89 << e.what() << std::endl; // NOLINT(performance-avoid-endl)
90 std::exit(1); // NOLINT(concurrency-mt-unsafe)
91 }
92}
93
95 util::StringView parameter_name, PlotOptions options) noexcept
97 try {
98 group_->config().add_plot(
99 std::make_shared<plots::ParameterToTimeBoxPlot>(
101 std::string(parameter_name.data(), parameter_name.size())),
102 options));
103 return *this;
104 } catch (const std::exception& e) {
105 std::cerr << "Failed to append a plot to a benchmark group: "
106 << e.what() << std::endl; // NOLINT(performance-avoid-endl)
107 std::exit(1); // NOLINT(concurrency-mt-unsafe)
108 }
109}
110
112 util::StringView parameter_name, util::StringView custom_output_name,
113 PlotOptions options) noexcept -> BenchmarkGroupRegister& {
114 try {
115 group_->config().add_plot(
116 std::make_shared<plots::ParameterToOutputLinePlot>(
118 std::string(parameter_name.data(), parameter_name.size())),
119 CustomOutputName(std::string(
120 custom_output_name.data(), custom_output_name.size())),
121 options));
122 return *this;
123 } catch (const std::exception& e) {
124 std::cerr << "Failed to append a plot to a benchmark group: "
125 << e.what() << std::endl; // NOLINT(performance-avoid-endl)
126 std::exit(1); // NOLINT(concurrency-mt-unsafe)
127 }
128}
129
131 util::StringView parameter_name, util::StringView custom_output_name,
132 PlotOptions options) noexcept -> BenchmarkGroupRegister& {
133 try {
134 group_->config().add_plot(
135 std::make_shared<plots::TimeToOutputByParameterLinePlot>(
137 std::string(parameter_name.data(), parameter_name.size())),
138 CustomOutputName(std::string(
139 custom_output_name.data(), custom_output_name.size())),
140 options));
141 return *this;
142 } catch (const std::exception& e) {
143 std::cerr << "Failed to append a plot to a benchmark group: "
144 << e.what() << std::endl; // NOLINT(performance-avoid-endl)
145 std::exit(1); // NOLINT(concurrency-mt-unsafe)
146 }
147}
148
149} // namespace bench_impl
150} // namespace stat_bench
Definition of BenchmarkCaseRegistry class.
Definition of BenchmarkGroupConfig class.
Definition of BenchmarkGroupName class.
Definition of BenchmarkGroup class.
Class of names of groups of benchmarks.
Class of names of custom outputs.
Class of options for plots.
static auto instance() -> BenchmarkCaseRegistry &
Get an instance of the registry.
auto add_parameter_to_output_line_plot(util::StringView parameter_name, util::StringView custom_output_name, PlotOptions options=PlotOptions()) noexcept -> BenchmarkGroupRegister &
Add a line plot of a custom output with respect to a parameter to the group.
auto add_parameter_to_time_line_plot(util::StringView parameter_name, PlotOptions options=PlotOptions()) noexcept -> BenchmarkGroupRegister &
Add a line plot of processing time with respect to a parameter to the group.
auto add_parameter_to_time_box_plot(util::StringView parameter_name, PlotOptions options=PlotOptions()) noexcept -> BenchmarkGroupRegister &
Add a box plot of processing time with respect to a parameter to the group.
auto add_time_to_output_by_parameter_line_plot(util::StringView parameter_name, util::StringView custom_output_name, PlotOptions options=PlotOptions()) noexcept -> BenchmarkGroupRegister &
Add a line plot of a custom output with respect to processing time while parameter changes.
auto add_parameter_to_time_violin_plot(util::StringView parameter_name, PlotOptions options=PlotOptions()) noexcept -> BenchmarkGroupRegister &
Add a violin plot of processing time with respect to a parameter to the group.
BenchmarkGroupRegister(const BenchmarkGroupName &name) noexcept
Constructor.
auto add_parameter_to_time_line_plot_log(util::StringView parameter_name) noexcept -> BenchmarkGroupRegister &
Add a line plot of processing time with respect to a parameter in the log scale to the group.
Class of names of parameters.
Class of view of strings.
Definition string_view.h:34
Definition of CustomOutputName class.
Namespace of internal implementation.
Namespace of stat_bench source codes.
Definition of ParameterName class.
Definition of ParameterToOutputLinePlot class.
Definition of ParameterToTimeBoxPlot class.
Definition of ParameterToTimeLinePlot class.
Definition of ParameterToTimeViolinPlot class.
Declaration of check_glob_pattern function.
Definition of TimeToOutputByParameterLinePlot class.