fixed non-const reference arguments

This commit is contained in:
Ismael 2016-05-23 18:51:29 +02:00
parent 8afbf0ed38
commit 5f9823bd92
5 changed files with 45 additions and 45 deletions

View File

@ -52,7 +52,7 @@ class BenchmarkReporter {
complexity(O_None), complexity(O_None),
arg1(0), arg1(0),
arg2(0), arg2(0),
report_bigO(false), report_big_o(false),
report_rms(false) {} report_rms(false) {}
std::string benchmark_name; std::string benchmark_name;
@ -75,7 +75,7 @@ class BenchmarkReporter {
int arg2; int arg2;
// Inform print function whether the current run is a complexity report // Inform print function whether the current run is a complexity report
bool report_bigO; bool report_big_o;
bool report_rms; bool report_rms;
}; };
@ -105,8 +105,8 @@ class BenchmarkReporter {
virtual ~BenchmarkReporter(); virtual ~BenchmarkReporter();
protected: protected:
static void ComputeStats(const std::vector<Run> & reports, Run& mean, Run& stddev); static void ComputeStats(const std::vector<Run> & reports, Run* mean, Run* stddev);
static void ComputeBigO(const std::vector<Run> & reports, Run& bigO, Run& rms); static void ComputeBigO(const std::vector<Run> & reports, Run* bigO, Run* rms);
static TimeUnitMultiplier GetTimeUnitAndMultiplier(TimeUnit unit); static TimeUnitMultiplier GetTimeUnitAndMultiplier(TimeUnit unit);
static std::string GetBigO(BigO complexity); static std::string GetBigO(BigO complexity);
}; };

View File

@ -72,7 +72,7 @@ void ConsoleReporter::ReportRuns(const std::vector<Run>& reports) {
Run mean_data; Run mean_data;
Run stddev_data; Run stddev_data;
BenchmarkReporter::ComputeStats(reports, mean_data, stddev_data); BenchmarkReporter::ComputeStats(reports, &mean_data, &stddev_data);
// Output using PrintRun. // Output using PrintRun.
PrintRunData(mean_data); PrintRunData(mean_data);
@ -85,12 +85,12 @@ void ConsoleReporter::ReportComplexity(const std::vector<Run> & complexity_repor
return; return;
} }
Run bigO_data; Run big_o_data;
Run rms_data; Run rms_data;
BenchmarkReporter::ComputeBigO(complexity_reports, bigO_data, rms_data); BenchmarkReporter::ComputeBigO(complexity_reports, &big_o_data, &rms_data);
// Output using PrintRun. // Output using PrintRun.
PrintRunData(bigO_data); PrintRunData(big_o_data);
PrintRunData(rms_data); PrintRunData(rms_data);
} }
@ -115,8 +115,8 @@ void ConsoleReporter::PrintRunData(const Run& result) {
ColorPrintf(COLOR_GREEN, "%-*s ", ColorPrintf(COLOR_GREEN, "%-*s ",
name_field_width_, result.benchmark_name.c_str()); name_field_width_, result.benchmark_name.c_str());
if(result.report_bigO) { if(result.report_big_o) {
std::string big_o = result.report_bigO ? GetBigO(result.complexity) : ""; std::string big_o = result.report_big_o ? GetBigO(result.complexity) : "";
ColorPrintf(COLOR_YELLOW, "%10.4f %s %10.4f %s ", ColorPrintf(COLOR_YELLOW, "%10.4f %s %10.4f %s ",
result.real_accumulated_time * multiplier, result.real_accumulated_time * multiplier,
big_o.c_str(), big_o.c_str(),

View File

@ -57,7 +57,7 @@ void CSVReporter::ReportRuns(const std::vector<Run> & reports) {
if (reports.size() >= 2) { if (reports.size() >= 2) {
Run mean_data; Run mean_data;
Run stddev_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(mean_data);
reports_cp.push_back(stddev_data); reports_cp.push_back(stddev_data);
} }
@ -74,7 +74,7 @@ void CSVReporter::ReportComplexity(const std::vector<Run> & complexity_reports)
Run bigO_data; Run bigO_data;
Run rms_data; Run rms_data;
BenchmarkReporter::ComputeBigO(complexity_reports, bigO_data, rms_data); BenchmarkReporter::ComputeBigO(complexity_reports, &bigO_data, &rms_data);
// Output using PrintRun. // Output using PrintRun.
PrintRunData(bigO_data); PrintRunData(bigO_data);

View File

@ -100,7 +100,7 @@ void JSONReporter::ReportRuns(std::vector<Run> const& reports) {
if (reports.size() >= 2) { if (reports.size() >= 2) {
Run mean_data; Run mean_data;
Run stddev_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(mean_data);
reports_cp.push_back(stddev_data); reports_cp.push_back(stddev_data);
} }
@ -129,7 +129,7 @@ void JSONReporter::ReportComplexity(const std::vector<Run> & complexity_reports)
Run bigO_data; Run bigO_data;
Run rms_data; Run rms_data;
BenchmarkReporter::ComputeBigO(complexity_reports, bigO_data, rms_data); BenchmarkReporter::ComputeBigO(complexity_reports, &bigO_data, &rms_data);
// Output using PrintRun. // Output using PrintRun.
out << indent << "{\n"; out << indent << "{\n";

View File

@ -26,7 +26,7 @@ namespace benchmark {
void BenchmarkReporter::ComputeStats( void BenchmarkReporter::ComputeStats(
const std::vector<Run>& reports, const std::vector<Run>& 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"; CHECK(reports.size() >= 2) << "Cannot compute stats for less than 2 reports";
// Accumulators. // Accumulators.
Stat1_d real_accumulated_time_stat; Stat1_d real_accumulated_time_stat;
@ -50,38 +50,38 @@ void BenchmarkReporter::ComputeStats(
} }
// Get the data from the accumulator to BenchmarkReporter::Run's. // Get the data from the accumulator to BenchmarkReporter::Run's.
mean_data.benchmark_name = reports[0].benchmark_name + "_mean"; mean_data->benchmark_name = reports[0].benchmark_name + "_mean";
mean_data.iterations = run_iterations; mean_data->iterations = run_iterations;
mean_data.real_accumulated_time = real_accumulated_time_stat.Mean() * mean_data->real_accumulated_time = real_accumulated_time_stat.Mean() *
run_iterations; run_iterations;
mean_data.cpu_accumulated_time = cpu_accumulated_time_stat.Mean() * mean_data->cpu_accumulated_time = cpu_accumulated_time_stat.Mean() *
run_iterations; run_iterations;
mean_data.bytes_per_second = bytes_per_second_stat.Mean(); mean_data->bytes_per_second = bytes_per_second_stat.Mean();
mean_data.items_per_second = items_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 // 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++) { for (std::size_t i = 1; i < reports.size(); i++) {
if (reports[i].report_label != reports[0].report_label) { if (reports[i].report_label != reports[0].report_label) {
mean_data.report_label = ""; mean_data->report_label = "";
break; break;
} }
} }
stddev_data.benchmark_name = reports[0].benchmark_name + "_stddev"; stddev_data->benchmark_name = reports[0].benchmark_name + "_stddev";
stddev_data.report_label = mean_data.report_label; stddev_data->report_label = mean_data->report_label;
stddev_data.iterations = 0; stddev_data->iterations = 0;
stddev_data.real_accumulated_time = stddev_data->real_accumulated_time =
real_accumulated_time_stat.StdDev(); real_accumulated_time_stat.StdDev();
stddev_data.cpu_accumulated_time = stddev_data->cpu_accumulated_time =
cpu_accumulated_time_stat.StdDev(); cpu_accumulated_time_stat.StdDev();
stddev_data.bytes_per_second = bytes_per_second_stat.StdDev(); stddev_data->bytes_per_second = bytes_per_second_stat.StdDev();
stddev_data.items_per_second = items_per_second_stat.StdDev(); stddev_data->items_per_second = items_per_second_stat.StdDev();
} }
void BenchmarkReporter::ComputeBigO( void BenchmarkReporter::ComputeBigO(
const std::vector<Run>& reports, const std::vector<Run>& reports,
Run& bigO, Run& rms) { Run* big_o, Run* rms) {
CHECK(reports.size() >= 2) << "Cannot compute asymptotic complexity for less than 2 reports"; CHECK(reports.size() >= 2) << "Cannot compute asymptotic complexity for less than 2 reports";
// Accumulators. // Accumulators.
std::vector<int> N; std::vector<int> N;
@ -106,26 +106,26 @@ void BenchmarkReporter::ComputeBigO(
std::string benchmark_name = reports[0].benchmark_name.substr(0, reports[0].benchmark_name.find('/')); 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. // Get the data from the accumulator to BenchmarkReporter::Run's.
bigO.benchmark_name = benchmark_name + "_BigO"; big_o->benchmark_name = benchmark_name + "_BigO";
bigO.iterations = 0; big_o->iterations = 0;
bigO.real_accumulated_time = resultReal.coef; big_o->real_accumulated_time = resultReal.coef;
bigO.cpu_accumulated_time = resultCpu.coef; big_o->cpu_accumulated_time = resultCpu.coef;
bigO.report_bigO = true; big_o->report_big_o = true;
bigO.complexity = resultCpu.complexity; big_o->complexity = resultCpu.complexity;
double multiplier; double multiplier;
const char* timeLabel; const char* timeLabel;
std::tie(timeLabel, multiplier) = GetTimeUnitAndMultiplier(reports[0].time_unit); std::tie(timeLabel, multiplier) = GetTimeUnitAndMultiplier(reports[0].time_unit);
// Only add label to mean/stddev if it is same for all runs // Only add label to mean/stddev if it is same for all runs
bigO.report_label = reports[0].report_label; big_o->report_label = reports[0].report_label;
rms.benchmark_name = benchmark_name + "_RMS"; rms->benchmark_name = benchmark_name + "_RMS";
rms.report_label = bigO.report_label; rms->report_label = big_o->report_label;
rms.iterations = 0; rms->iterations = 0;
rms.real_accumulated_time = resultReal.rms / multiplier; rms->real_accumulated_time = resultReal.rms / multiplier;
rms.cpu_accumulated_time = resultCpu.rms / multiplier; rms->cpu_accumulated_time = resultCpu.rms / multiplier;
rms.report_rms = true; rms->report_rms = true;
rms.complexity = resultCpu.complexity; rms->complexity = resultCpu.complexity;
} }
std::string BenchmarkReporter::GetBigO(BigO complexity) { std::string BenchmarkReporter::GetBigO(BigO complexity) {