cpp-stat-bench 0.24.0
Benchmark library with statistics for C++.
Loading...
Searching...
No Matches
parameter_to_time_violin_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/violin.h>
30#include <plotly_plotter/write_html.h>
31
32#include "common_labels.h"
33#include "create_data_table.h"
37
38namespace stat_bench {
39namespace plots {
40
42 param::ParameterName parameter_name, PlotOptions options)
43 : parameter_name_(std::move(parameter_name)),
44 options_(options),
45 name_for_file_(create_name_for_file(parameter_name_, options_)) {}
46
48 -> const util::Utf8String& {
49 return name_for_file_;
50}
51
53 const measurer::MeasurerName& measurer_name,
54 const BenchmarkGroupName& group_name,
55 const std::vector<measurer::Measurement>& measurements,
56 const std::string& file_path) {
57 (void)group_name;
58
59 const auto& title = measurer_name.str();
60
61 std::vector<param::ParameterName> parameter_names;
62 parameter_names.push_back(parameter_name_);
63 if (!options_.subplot_column_parameter_name().empty()) {
64 parameter_names.emplace_back(
65 options_.subplot_column_parameter_name().data());
66 }
67 if (!options_.subplot_row_parameter_name().empty()) {
68 parameter_names.emplace_back(
69 options_.subplot_row_parameter_name().data());
70 }
71
72 const auto data_table =
73 create_data_table_with_all_time(measurements, parameter_names);
74 auto figure_builder = plotly_plotter::figure_builders::violin(data_table)
75 .x(parameter_name_.str().str())
76 .y(time_label)
77 .group(case_name_label)
78 .log_y(true)
79 .show_box(true)
80 .show_mean_line(true);
81 if (!options_.subplot_column_parameter_name().empty()) {
82 figure_builder.subplot_column(
83 options_.subplot_column_parameter_name().data());
84 }
85 if (!options_.subplot_row_parameter_name().empty()) {
86 figure_builder.subplot_row(
87 options_.subplot_row_parameter_name().data());
88 }
89 auto figure = figure_builder.create();
90 figure.title(title.str());
91 plotly_plotter::write_html(file_path, figure);
92}
93
94auto ParameterToTimeViolinPlot::create_name_for_file(
95 const param::ParameterName& parameter_name, const PlotOptions& options)
97 fmt::memory_buffer buffer;
98 fmt::format_to(std::back_inserter(buffer), "by_{}_violin",
99 util::escape_for_file_name(parameter_name.str()));
100 if (!options.subplot_column_parameter_name().empty()) {
101 fmt::format_to(std::back_inserter(buffer), "_by_{}",
103 options.subplot_column_parameter_name().data())));
104 }
105 if (!options.subplot_row_parameter_name().empty()) {
106 fmt::format_to(std::back_inserter(buffer), "_by_{}",
108 util::Utf8String(options.subplot_row_parameter_name().data())));
109 }
110 return util::Utf8String(std::string(buffer.data(), buffer.size()));
111}
112
113} // namespace plots
114} // namespace stat_bench
Class of names of groups of benchmarks.
Class of options for plots.
Class of names of measurers.
auto str() const noexcept -> const util::Utf8String &
Get the string of the name.
Class of names of parameters.
auto name_for_file() const -> const util::Utf8String &override
Get a name for output files.
void write(const measurer::MeasurerName &measurer_name, const BenchmarkGroupName &group_name, const std::vector< measurer::Measurement > &measurements, const std::string &file_path) override
Write a plot.
ParameterToTimeViolinPlot(param::ParameterName parameter_name, PlotOptions options)
Constructor.
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.
Definition of MeasurerName class.
Namespace of plotting.
Definition box_plot.h:28
constexpr const char * time_label
Label for processing time in plots.
constexpr const char * case_name_label
Label for case names in plots.
auto create_data_table_with_all_time(const std::vector< measurer::Measurement > &measurements, const std::vector< param::ParameterName > &parameter_names) -> plotly_plotter::data_table
Create a data table with all samples of processing time.
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.
Definition of ParameterToTimeViolinPlot class.
Declaration of check_glob_pattern function.