diff --git a/include/benchmark/reporter.h b/include/benchmark/reporter.h index 3bf45d87..564219a1 100644 --- a/include/benchmark/reporter.h +++ b/include/benchmark/reporter.h @@ -52,7 +52,7 @@ class BenchmarkReporter { complexity(O_None), arg1(0), arg2(0), - report_bigO(false), + report_big_o(false), report_rms(false) {} std::string benchmark_name; @@ -75,7 +75,7 @@ class BenchmarkReporter { int arg2; // Inform print function whether the current run is a complexity report - bool report_bigO; + bool report_big_o; bool report_rms; }; @@ -105,8 +105,8 @@ class BenchmarkReporter { virtual ~BenchmarkReporter(); protected: - static void ComputeStats(const std::vector & reports, Run& mean, Run& stddev); - static void ComputeBigO(const std::vector & reports, Run& bigO, Run& rms); + static void ComputeStats(const std::vector & reports, Run* mean, Run* stddev); + static void ComputeBigO(const std::vector & reports, Run* bigO, Run* rms); static TimeUnitMultiplier GetTimeUnitAndMultiplier(TimeUnit unit); static std::string GetBigO(BigO complexity); }; diff --git a/src/console_reporter.cc b/src/console_reporter.cc index b0b41309..09b91c2b 100644 --- a/src/console_reporter.cc +++ b/src/console_reporter.cc @@ -72,7 +72,7 @@ void ConsoleReporter::ReportRuns(const std::vector& reports) { Run mean_data; Run stddev_data; - BenchmarkReporter::ComputeStats(reports, mean_data, stddev_data); + BenchmarkReporter::ComputeStats(reports, &mean_data, &stddev_data); // Output using PrintRun. PrintRunData(mean_data); @@ -85,12 +85,12 @@ void ConsoleReporter::ReportComplexity(const std::vector & complexity_repor return; } - Run bigO_data; + Run big_o_data; Run rms_data; - BenchmarkReporter::ComputeBigO(complexity_reports, bigO_data, rms_data); + BenchmarkReporter::ComputeBigO(complexity_reports, &big_o_data, &rms_data); // Output using PrintRun. - PrintRunData(bigO_data); + PrintRunData(big_o_data); PrintRunData(rms_data); } @@ -115,8 +115,8 @@ void ConsoleReporter::PrintRunData(const Run& result) { ColorPrintf(COLOR_GREEN, "%-*s ", name_field_width_, result.benchmark_name.c_str()); - if(result.report_bigO) { - std::string big_o = result.report_bigO ? GetBigO(result.complexity) : ""; + if(result.report_big_o) { + std::string big_o = result.report_big_o ? GetBigO(result.complexity) : ""; ColorPrintf(COLOR_YELLOW, "%10.4f %s %10.4f %s ", result.real_accumulated_time * multiplier, big_o.c_str(), diff --git a/src/csv_reporter.cc b/src/csv_reporter.cc index f13a5f8b..031736e5 100644 --- a/src/csv_reporter.cc +++ b/src/csv_reporter.cc @@ -57,7 +57,7 @@ void CSVReporter::ReportRuns(const std::vector & reports) { if (reports.size() >= 2) { Run mean_data; Run stddev_data; - BenchmarkReporter::ComputeStats(reports, mean_data, stddev_data); + BenchmarkReporter::ComputeStats(reports, &mean_data, &stddev_data); reports_cp.push_back(mean_data); reports_cp.push_back(stddev_data); } @@ -74,7 +74,7 @@ void CSVReporter::ReportComplexity(const std::vector & complexity_reports) Run bigO_data; Run rms_data; - BenchmarkReporter::ComputeBigO(complexity_reports, bigO_data, rms_data); + BenchmarkReporter::ComputeBigO(complexity_reports, &bigO_data, &rms_data); // Output using PrintRun. PrintRunData(bigO_data); diff --git a/src/json_reporter.cc b/src/json_reporter.cc index 4874fe74..c15fb105 100644 --- a/src/json_reporter.cc +++ b/src/json_reporter.cc @@ -100,7 +100,7 @@ void JSONReporter::ReportRuns(std::vector const& reports) { if (reports.size() >= 2) { Run mean_data; Run stddev_data; - BenchmarkReporter::ComputeStats(reports, mean_data, stddev_data); + BenchmarkReporter::ComputeStats(reports, &mean_data, &stddev_data); reports_cp.push_back(mean_data); reports_cp.push_back(stddev_data); } @@ -129,7 +129,7 @@ void JSONReporter::ReportComplexity(const std::vector & complexity_reports) Run bigO_data; Run rms_data; - BenchmarkReporter::ComputeBigO(complexity_reports, bigO_data, rms_data); + BenchmarkReporter::ComputeBigO(complexity_reports, &bigO_data, &rms_data); // Output using PrintRun. out << indent << "{\n"; diff --git a/src/reporter.cc b/src/reporter.cc index 61a6d5c3..27dca856 100644 --- a/src/reporter.cc +++ b/src/reporter.cc @@ -26,7 +26,7 @@ namespace benchmark { void BenchmarkReporter::ComputeStats( const std::vector& reports, - Run& mean_data, Run& stddev_data) { + Run* mean_data, Run* stddev_data) { CHECK(reports.size() >= 2) << "Cannot compute stats for less than 2 reports"; // Accumulators. Stat1_d real_accumulated_time_stat; @@ -50,38 +50,38 @@ void BenchmarkReporter::ComputeStats( } // Get the data from the accumulator to BenchmarkReporter::Run's. - mean_data.benchmark_name = reports[0].benchmark_name + "_mean"; - mean_data.iterations = run_iterations; - mean_data.real_accumulated_time = real_accumulated_time_stat.Mean() * + mean_data->benchmark_name = reports[0].benchmark_name + "_mean"; + mean_data->iterations = run_iterations; + mean_data->real_accumulated_time = real_accumulated_time_stat.Mean() * run_iterations; - mean_data.cpu_accumulated_time = cpu_accumulated_time_stat.Mean() * + mean_data->cpu_accumulated_time = cpu_accumulated_time_stat.Mean() * run_iterations; - mean_data.bytes_per_second = bytes_per_second_stat.Mean(); - mean_data.items_per_second = items_per_second_stat.Mean(); + mean_data->bytes_per_second = bytes_per_second_stat.Mean(); + mean_data->items_per_second = items_per_second_stat.Mean(); // Only add label to mean/stddev if it is same for all runs - mean_data.report_label = reports[0].report_label; + mean_data->report_label = reports[0].report_label; for (std::size_t i = 1; i < reports.size(); i++) { if (reports[i].report_label != reports[0].report_label) { - mean_data.report_label = ""; + mean_data->report_label = ""; break; } } - stddev_data.benchmark_name = reports[0].benchmark_name + "_stddev"; - stddev_data.report_label = mean_data.report_label; - stddev_data.iterations = 0; - stddev_data.real_accumulated_time = + stddev_data->benchmark_name = reports[0].benchmark_name + "_stddev"; + stddev_data->report_label = mean_data->report_label; + stddev_data->iterations = 0; + stddev_data->real_accumulated_time = real_accumulated_time_stat.StdDev(); - stddev_data.cpu_accumulated_time = + stddev_data->cpu_accumulated_time = cpu_accumulated_time_stat.StdDev(); - stddev_data.bytes_per_second = bytes_per_second_stat.StdDev(); - stddev_data.items_per_second = items_per_second_stat.StdDev(); + stddev_data->bytes_per_second = bytes_per_second_stat.StdDev(); + stddev_data->items_per_second = items_per_second_stat.StdDev(); } void BenchmarkReporter::ComputeBigO( const std::vector& reports, - Run& bigO, Run& rms) { + Run* big_o, Run* rms) { CHECK(reports.size() >= 2) << "Cannot compute asymptotic complexity for less than 2 reports"; // Accumulators. std::vector N; @@ -106,26 +106,26 @@ void BenchmarkReporter::ComputeBigO( std::string benchmark_name = reports[0].benchmark_name.substr(0, reports[0].benchmark_name.find('/')); // Get the data from the accumulator to BenchmarkReporter::Run's. - bigO.benchmark_name = benchmark_name + "_BigO"; - bigO.iterations = 0; - bigO.real_accumulated_time = resultReal.coef; - bigO.cpu_accumulated_time = resultCpu.coef; - bigO.report_bigO = true; - bigO.complexity = resultCpu.complexity; + big_o->benchmark_name = benchmark_name + "_BigO"; + big_o->iterations = 0; + big_o->real_accumulated_time = resultReal.coef; + big_o->cpu_accumulated_time = resultCpu.coef; + big_o->report_big_o = true; + big_o->complexity = resultCpu.complexity; double multiplier; const char* timeLabel; std::tie(timeLabel, multiplier) = GetTimeUnitAndMultiplier(reports[0].time_unit); // Only add label to mean/stddev if it is same for all runs - bigO.report_label = reports[0].report_label; - rms.benchmark_name = benchmark_name + "_RMS"; - rms.report_label = bigO.report_label; - rms.iterations = 0; - rms.real_accumulated_time = resultReal.rms / multiplier; - rms.cpu_accumulated_time = resultCpu.rms / multiplier; - rms.report_rms = true; - rms.complexity = resultCpu.complexity; + big_o->report_label = reports[0].report_label; + rms->benchmark_name = benchmark_name + "_RMS"; + rms->report_label = big_o->report_label; + rms->iterations = 0; + rms->real_accumulated_time = resultReal.rms / multiplier; + rms->cpu_accumulated_time = resultCpu.rms / multiplier; + rms->report_rms = true; + rms->complexity = resultCpu.complexity; } std::string BenchmarkReporter::GetBigO(BigO complexity) {