cpp-stat-bench 0.24.0
Benchmark library with statistics for C++.
Loading...
Searching...
No Matches
data_file_helper.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 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 <functional>
24
30
31namespace stat_bench {
32namespace reporter {
33namespace data_file_spec {
34
35auto convert(const param::ParameterDict& params)
36 -> std::unordered_map<util::Utf8String, util::Utf8String> {
37 return params.as_string_dict();
38}
39
41 return StatData{static_cast<float>(stat.mean()),
42 static_cast<float>(stat.max()), static_cast<float>(stat.min()),
43 static_cast<float>(stat.median()), static_cast<float>(stat.variance()),
44 static_cast<float>(stat.standard_deviation()),
45 static_cast<float>(stat.standard_error())};
46}
47
48auto convert(const std::vector<std::vector<clock::Duration>>& durations,
49 const stat::Statistics& durations_stat) -> DurationData {
50 std::vector<std::vector<float>> values;
51 values.reserve(durations.size());
52 for (const auto& durations_per_thread : durations) {
53 values.emplace_back();
54 auto& values_per_thread = values.back();
55 values_per_thread.reserve(durations_per_thread.size());
56 for (const auto& duration : durations_per_thread) {
57 values_per_thread.push_back(static_cast<float>(duration.seconds()));
58 }
59 }
60 return DurationData{convert(durations_stat), std::move(values)};
61}
62
63auto convert(const std::shared_ptr<stat::CustomStatOutput>& stat_output,
65 std::vector<std::vector<float>> data;
66 data.reserve(stat_output->data().size());
67 for (const auto& vec : stat_output->data()) {
68 std::vector<float> vec_copy;
69 vec_copy.reserve(vec.size());
70 for (const double val : vec) {
71 vec_copy.push_back(static_cast<float>(val));
72 }
73 data.push_back(std::move(vec_copy));
74 }
75 return CustomStatOutputData{stat_output->name().str(), convert(stat), data};
76}
77
79 const std::vector<std::shared_ptr<stat::CustomStatOutput>>& stat_outputs,
80 const std::vector<stat::Statistics>& stats)
81 -> std::vector<CustomStatOutputData> {
82 std::vector<CustomStatOutputData> data;
83 data.reserve(stat_outputs.size());
84 for (std::size_t i = 0; i < stat_outputs.size(); ++i) {
85 data.push_back(convert(stat_outputs.at(i), stats.at(i)));
86 }
87 return data;
88}
89
90auto convert(const std::vector<std::pair<CustomOutputName, double>>& outputs)
91 -> std::vector<CustomOutputData> {
92 std::vector<CustomOutputData> data;
93 data.reserve(outputs.size());
94 for (const auto& output : outputs) {
95 data.push_back(CustomOutputData{
96 output.first.str(), static_cast<float>(output.second)});
97 }
98 return data;
99}
100
101auto convert(const measurer::Measurement& measurement) -> MeasurementData {
102 return MeasurementData{measurement.case_info().group_name().str(),
103 measurement.case_info().case_name().str(),
104 convert(measurement.cond().params()), measurement.measurer_name().str(),
105 measurement.iterations(), measurement.samples(),
106 convert(measurement.durations(), measurement.durations_stat()),
107 convert(measurement.custom_stat_outputs(), measurement.custom_stat()),
108 convert(measurement.custom_outputs())};
109}
110
111} // namespace data_file_spec
112} // namespace reporter
113} // namespace stat_bench
Definition of BenchmarkCaseName class.
Definition of BenchmarkCondition class.
Definition of BenchmarkFullName class.
Definition of BenchmarkGroupName class.
Class of data of measurements.
Definition measurement.h:42
Class of dictionaries of parameters.
Class to calculate statistics.
Definition statistics.h:31
Declaration of functions to help output of data files.
Definition of MeasurerName class.
Namespace of specification of data files.
auto convert(const param::ParameterDict &params) -> std::unordered_map< util::Utf8String, util::Utf8String >
Convert to data for data files.
Namespace of reporters of results of benchmarks.
Namespace of statistics.
Definition calc_stat.h:29
Namespace of stat_bench source codes.
Struct of custom outputs without statistics.
Struct of custom outputs with statistics.