18 #include "benchmark/benchmark.h"
29 static const double kLog2E = 1.44269504088896340736;
83 const std::vector<double>& time,
85 double sigma_gn_squared = 0.0;
86 double sigma_time = 0.0;
87 double sigma_time_gn = 0.0;
90 for (
size_t i = 0;
i <
n.size(); ++
i) {
91 double gn_i = fitting_curve(
n[
i]);
92 sigma_gn_squared += gn_i * gn_i;
93 sigma_time += time[
i];
94 sigma_time_gn += time[
i] * gn_i;
101 result.coef = sigma_time_gn / sigma_gn_squared;
105 for (
size_t i = 0;
i <
n.size(); ++
i) {
106 double fit =
result.coef * fitting_curve(
n[
i]);
107 rms += pow((time[
i] - fit), 2);
111 double mean = sigma_time /
n.size();
112 result.rms = sqrt(rms /
n.size()) / mean;
125 const std::vector<double>& time,
const BigO complexity) {
133 if (complexity ==
oAuto) {
141 for (
const auto& fit : fit_curves) {
143 if (current_fit.
rms < best_fit.
rms) {
144 best_fit = current_fit;
157 const std::vector<BenchmarkReporter::Run>& reports) {
161 if (reports.size() < 2)
return results;
164 std::vector<int64_t>
n;
165 std::vector<double> real_time;
166 std::vector<double> cpu_time;
169 for (
const Run&
run : reports) {
171 <<
"Did you forget to call SetComplexityN?";
172 n.push_back(
run.complexity_n);
173 real_time.push_back(
run.real_accumulated_time /
run.iterations);
174 cpu_time.push_back(
run.cpu_accumulated_time /
run.iterations);
180 if (reports[0].complexity ==
oLambda) {
181 result_cpu =
MinimalLeastSq(
n, cpu_time, reports[0].complexity_lambda);
182 result_real =
MinimalLeastSq(
n, real_time, reports[0].complexity_lambda);
189 auto run_name = reports[0].run_name;
190 run_name.args.clear();
194 big_o.run_name = run_name;
195 big_o.family_index = reports[0].family_index;
196 big_o.per_family_instance_index = reports[0].per_family_instance_index;
198 big_o.repetitions = reports[0].repetitions;
199 big_o.repetition_index = Run::no_repetition_index;
200 big_o.threads = reports[0].threads;
201 big_o.aggregate_name =
"BigO";
203 big_o.report_label = reports[0].report_label;
204 big_o.iterations = 0;
205 big_o.real_accumulated_time = result_real.
coef;
206 big_o.cpu_accumulated_time = result_cpu.
coef;
207 big_o.report_big_o =
true;
219 rms.run_name = run_name;
220 rms.family_index = reports[0].family_index;
221 rms.per_family_instance_index = reports[0].per_family_instance_index;
223 rms.aggregate_name =
"RMS";
225 rms.report_label = big_o.report_label;
227 rms.repetition_index = Run::no_repetition_index;
228 rms.repetitions = reports[0].repetitions;
229 rms.threads = reports[0].threads;
230 rms.real_accumulated_time = result_real.
rms / multiplier;
231 rms.cpu_accumulated_time = result_cpu.
rms / multiplier;
232 rms.report_rms =
true;
236 rms.time_unit = reports[0].time_unit;