cpp-stat-bench 0.24.0
Benchmark library with statistics for C++.
Loading...
Searching...
No Matches
time_to_output_by_parameter_line_plot.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 <iterator>
23#include <utility>
24#include <vector>
25
26#include <fmt/base.h>
27#include <fmt/format.h>
28#include <plotly_plotter/figure.h>
29#include <plotly_plotter/figure_builders/line.h>
30#include <plotly_plotter/figure_builders/scatter.h>
31#include <plotly_plotter/write_html.h>
32
33#include "common_labels.h"
34#include "create_data_table.h"
37
38namespace stat_bench {
39namespace plots {
40
42 param::ParameterName parameter_name, CustomOutputName custom_output_name,
43 PlotOptions options)
44 : parameter_name_(std::move(parameter_name)),
45 custom_output_name_(std::move(custom_output_name)),
46 options_(options),
47 name_for_file_(create_name_for_file(
48 parameter_name_, custom_output_name_, options_)) {}
49
51 -> const util::Utf8String& {
52 return name_for_file_;
53}
54
56 const measurer::MeasurementType& measurement_type,
57 const BenchmarkGroupName& group_name,
58 const std::vector<measurer::Measurement>& measurements,
59 const std::string& file_path) {
60 (void)measurement_type;
61 (void)group_name;
62
63 const auto& title = custom_output_name_.str();
64
65 std::vector<param::ParameterName> parameter_names;
66 parameter_names.push_back(parameter_name_);
67 if (!options_.subplot_column_parameter_name().empty()) {
68 parameter_names.emplace_back(
69 options_.subplot_column_parameter_name().data());
70 }
71 if (!options_.subplot_row_parameter_name().empty()) {
72 parameter_names.emplace_back(
73 options_.subplot_row_parameter_name().data());
74 }
75
76 const auto [data_table, has_error] = create_data_table_with_custom_output(
77 measurements, parameter_names, custom_output_name_);
78 auto figure_builder = plotly_plotter::figure_builders::line(data_table)
79 .x(time_label)
80 .error_x(time_error_label)
81 .y(custom_output_name_.str().str())
82 .group(case_name_label)
83 .log_x(true)
84 .log_y(options_.log_output())
85 .hover_data({parameter_name_.str().str()});
86 if (has_error) {
87 figure_builder.error_y(fmt::format("Error of {}", custom_output_name_));
88 }
89 if (!options_.subplot_column_parameter_name().empty()) {
90 figure_builder.subplot_column(
91 options_.subplot_column_parameter_name().data());
92 }
93 if (!options_.subplot_row_parameter_name().empty()) {
94 figure_builder.subplot_row(
95 options_.subplot_row_parameter_name().data());
96 }
97 auto figure = figure_builder.create();
98 figure.title(title.str());
99 plotly_plotter::write_html(file_path, figure);
100}
101
102auto TimeToOutputByParameterLinePlot::create_name_for_file(
103 const param::ParameterName& parameter_name,
104 const CustomOutputName& custom_output_name, const PlotOptions& options)
106 fmt::memory_buffer buffer;
107 fmt::format_to(std::back_inserter(buffer), "to_{}_by_{}",
108 util::escape_for_file_name(custom_output_name.str()),
109 util::escape_for_file_name(parameter_name.str()));
110 if (!options.subplot_column_parameter_name().empty()) {
111 fmt::format_to(std::back_inserter(buffer), "_by_{}",
113 options.subplot_column_parameter_name().data())));
114 }
115 if (!options.subplot_row_parameter_name().empty()) {
116 fmt::format_to(std::back_inserter(buffer), "_by_{}",
118 util::Utf8String(options.subplot_row_parameter_name().data())));
119 }
120 return util::Utf8String(std::string(buffer.data(), buffer.size()));
121}
122
123} // namespace plots
124} // namespace stat_bench
Class of names of groups of benchmarks.
auto str() const noexcept -> const util::Utf8String &
Get the string of the name.
Class of names of custom outputs.
Class of options for plots.
Class of names of measurement types.
Class of names of parameters.
void write(const measurer::MeasurementType &measurement_type, const BenchmarkGroupName &group_name, const std::vector< measurer::Measurement > &measurements, const std::string &file_path) override
Write a plot.
TimeToOutputByParameterLinePlot(param::ParameterName parameter_name, CustomOutputName custom_output_name, PlotOptions options)
Constructor.
auto name_for_file() const -> const util::Utf8String &override
Get a name for output files.
Class of UTF-8 encoded string.
Definition utf8_string.h:35
Definition of constants for labels in plots.
Declaration of create_data_table function.
Declaration of escape_for_file_name function.
Namespace of plotting.
Definition box_plot.h:28
constexpr const char * time_label
Label for processing time in plots.
auto create_data_table_with_custom_output(const std::vector< measurer::Measurement > &measurements, const std::vector< param::ParameterName > &parameter_names, const CustomOutputName &output_name) -> std::pair< plotly_plotter::data_table, bool >
Create a data table with a custom output.
constexpr const char * time_error_label
Label for errors of processing time in plots.
constexpr const char * case_name_label
Label for case names in plots.
Namespace of utility functions and classes.
auto escape_for_file_name(const Utf8String &input) -> Utf8String
Escape a string for a file name.
Namespace of stat_bench source codes.
STL namespace.
Declaration of check_glob_pattern function.
Definition of TimeToOutputByParameterLinePlot class.