google formated

This commit is contained in:
Ismael 2016-06-02 22:01:31 +02:00
parent 109f528a40
commit 22cb9d9ce0
5 changed files with 138 additions and 139 deletions

View file

@ -148,7 +148,7 @@ class BenchmarkReporter {
// REQUIRES: 'out' is non-null. // REQUIRES: 'out' is non-null.
static void PrintBasicContext(std::ostream* out, Context const& context); static void PrintBasicContext(std::ostream* out, Context const& context);
private: private:
std::ostream* output_stream_; std::ostream* output_stream_;
std::ostream* error_stream_; std::ostream* error_stream_;
}; };
@ -156,35 +156,35 @@ private:
// Simple reporter that outputs benchmark data to the console. This is the // Simple reporter that outputs benchmark data to the console. This is the
// default reporter used by RunSpecifiedBenchmarks(). // default reporter used by RunSpecifiedBenchmarks().
class ConsoleReporter : public BenchmarkReporter { class ConsoleReporter : public BenchmarkReporter {
public: public:
virtual bool ReportContext(const Context& context); virtual bool ReportContext(const Context& context);
virtual void ReportRuns(const std::vector<Run>& reports); virtual void ReportRuns(const std::vector<Run>& reports);
protected: protected:
virtual void PrintRunData(const Run& report); virtual void PrintRunData(const Run& report);
size_t name_field_width_; size_t name_field_width_;
}; };
class JSONReporter : public BenchmarkReporter { class JSONReporter : public BenchmarkReporter {
public: public:
JSONReporter() : first_report_(true) {} JSONReporter() : first_report_(true) {}
virtual bool ReportContext(const Context& context); virtual bool ReportContext(const Context& context);
virtual void ReportRuns(const std::vector<Run>& reports); virtual void ReportRuns(const std::vector<Run>& reports);
virtual void Finalize(); virtual void Finalize();
private: private:
void PrintRunData(const Run& report); void PrintRunData(const Run& report);
bool first_report_; bool first_report_;
}; };
class CSVReporter : public BenchmarkReporter { class CSVReporter : public BenchmarkReporter {
public: public:
virtual bool ReportContext(const Context& context); virtual bool ReportContext(const Context& context);
virtual void ReportRuns(const std::vector<Run>& reports); virtual void ReportRuns(const std::vector<Run>& reports);
private: private:
void PrintRunData(const Run& report); void PrintRunData(const Run& report);
}; };

View file

@ -17,11 +17,11 @@
#include "benchmark/benchmark_api.h" #include "benchmark/benchmark_api.h"
#include "complexity.h"
#include "check.h"
#include "stat.h"
#include <cmath>
#include <algorithm> #include <algorithm>
#include <cmath>
#include "check.h"
#include "complexity.h"
#include "stat.h"
namespace benchmark { namespace benchmark {
@ -29,18 +29,18 @@ namespace benchmark {
BigOFunc* FittingCurve(BigO complexity) { BigOFunc* FittingCurve(BigO complexity) {
switch (complexity) { switch (complexity) {
case oN: case oN:
return [](size_t n) -> double {return n; }; return [](size_t n) -> double { return n; };
case oNSquared: case oNSquared:
return [](size_t n) -> double {return n * n; }; return [](size_t n) -> double { return n * n; };
case oNCubed: case oNCubed:
return [](size_t n) -> double {return n * n * n; }; return [](size_t n) -> double { return n * n * n; };
case oLogN: case oLogN:
return [](size_t n) {return log2(n); }; return [](size_t n) { return log2(n); };
case oNLogN: case oNLogN:
return [](size_t n) {return n * log2(n); }; return [](size_t n) { return n * log2(n); };
case o1: case o1:
default: default:
return [](size_t) {return 1.0; }; return [](size_t) { return 1.0; };
} }
} }
@ -122,14 +122,14 @@ LeastSq MinimalLeastSq(const std::vector<int>& n,
const std::vector<double>& time, const std::vector<double>& time,
const BigO complexity) { const BigO complexity) {
CHECK_EQ(n.size(), time.size()); CHECK_EQ(n.size(), time.size());
CHECK_GE(n.size(), 2); // Do not compute fitting curve is less than two benchmark runs are given CHECK_GE(n.size(), 2); // Do not compute fitting curve is less than two
// benchmark runs are given
CHECK_NE(complexity, oNone); CHECK_NE(complexity, oNone);
LeastSq best_fit; LeastSq best_fit;
if(complexity == oAuto) { if (complexity == oAuto) {
std::vector<BigO> fit_curves = { std::vector<BigO> fit_curves = {oLogN, oN, oNLogN, oNSquared, oNCubed};
oLogN, oN, oNLogN, oNSquared, oNCubed };
// Take o1 as default best fitting curve // Take o1 as default best fitting curve
best_fit = MinimalLeastSq(n, time, FittingCurve(o1)); best_fit = MinimalLeastSq(n, time, FittingCurve(o1));
@ -152,14 +152,13 @@ LeastSq MinimalLeastSq(const std::vector<int>& n,
} }
std::vector<BenchmarkReporter::Run> ComputeStats( std::vector<BenchmarkReporter::Run> ComputeStats(
const std::vector<BenchmarkReporter::Run>& reports) const std::vector<BenchmarkReporter::Run>& reports) {
{
typedef BenchmarkReporter::Run Run; typedef BenchmarkReporter::Run Run;
std::vector<Run> results; std::vector<Run> results;
auto error_count = std::count_if( auto error_count =
reports.begin(), reports.end(), std::count_if(reports.begin(), reports.end(),
[](Run const& run) {return run.error_occurred;}); [](Run const& run) { return run.error_occurred; });
if (reports.size() - error_count < 2) { if (reports.size() - error_count < 2) {
// We don't report aggregated data if there was a single run. // We don't report aggregated data if there was a single run.
@ -178,12 +177,11 @@ std::vector<BenchmarkReporter::Run> ComputeStats(
for (Run const& run : reports) { for (Run const& run : reports) {
CHECK_EQ(reports[0].benchmark_name, run.benchmark_name); CHECK_EQ(reports[0].benchmark_name, run.benchmark_name);
CHECK_EQ(run_iterations, run.iterations); CHECK_EQ(run_iterations, run.iterations);
if (run.error_occurred) if (run.error_occurred) continue;
continue;
real_accumulated_time_stat += real_accumulated_time_stat +=
Stat1_d(run.real_accumulated_time/run.iterations, run.iterations); Stat1_d(run.real_accumulated_time / run.iterations, run.iterations);
cpu_accumulated_time_stat += cpu_accumulated_time_stat +=
Stat1_d(run.cpu_accumulated_time/run.iterations, run.iterations); Stat1_d(run.cpu_accumulated_time / run.iterations, run.iterations);
items_per_second_stat += Stat1_d(run.items_per_second, run.iterations); items_per_second_stat += Stat1_d(run.items_per_second, run.iterations);
bytes_per_second_stat += Stat1_d(run.bytes_per_second, run.iterations); bytes_per_second_stat += Stat1_d(run.bytes_per_second, run.iterations);
} }
@ -192,10 +190,10 @@ std::vector<BenchmarkReporter::Run> ComputeStats(
Run mean_data; Run mean_data;
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 =
run_iterations; real_accumulated_time_stat.Mean() * run_iterations;
mean_data.cpu_accumulated_time = cpu_accumulated_time_stat.Mean() * mean_data.cpu_accumulated_time =
run_iterations; cpu_accumulated_time_stat.Mean() * 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();
@ -212,10 +210,8 @@ std::vector<BenchmarkReporter::Run> ComputeStats(
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 = cpu_accumulated_time_stat.StdDev();
stddev_data.cpu_accumulated_time =
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();
@ -225,8 +221,7 @@ std::vector<BenchmarkReporter::Run> ComputeStats(
} }
std::vector<BenchmarkReporter::Run> ComputeBigO( std::vector<BenchmarkReporter::Run> ComputeBigO(
const std::vector<BenchmarkReporter::Run>& reports) const std::vector<BenchmarkReporter::Run>& reports) {
{
typedef BenchmarkReporter::Run Run; typedef BenchmarkReporter::Run Run;
std::vector<Run> results; std::vector<Run> results;
@ -240,8 +235,8 @@ std::vector<BenchmarkReporter::Run> ComputeBigO(
// Populate the accumulators. // Populate the accumulators.
for (const Run& run : reports) { for (const Run& run : reports) {
n.push_back(run.complexity_n); n.push_back(run.complexity_n);
real_time.push_back(run.real_accumulated_time/run.iterations); real_time.push_back(run.real_accumulated_time / run.iterations);
cpu_time.push_back(run.cpu_accumulated_time/run.iterations); cpu_time.push_back(run.cpu_accumulated_time / run.iterations);
} }
LeastSq result_cpu; LeastSq result_cpu;
@ -254,7 +249,8 @@ std::vector<BenchmarkReporter::Run> ComputeBigO(
result_cpu = MinimalLeastSq(n, cpu_time, reports[0].complexity_lambda); result_cpu = MinimalLeastSq(n, cpu_time, reports[0].complexity_lambda);
result_real = MinimalLeastSq(n, real_time, reports[0].complexity_lambda); result_real = MinimalLeastSq(n, real_time, reports[0].complexity_lambda);
} }
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.
Run big_o; Run big_o;

View file

@ -15,9 +15,9 @@
#include "benchmark/reporter.h" #include "benchmark/reporter.h"
#include "complexity.h" #include "complexity.h"
#include <algorithm>
#include <cstdint> #include <cstdint>
#include <cstdio> #include <cstdio>
#include <algorithm>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <tuple> #include <tuple>
@ -62,8 +62,8 @@ void ConsoleReporter::ReportRuns(const std::vector<Run>& reports) {
void ConsoleReporter::PrintRunData(const Run& result) { void ConsoleReporter::PrintRunData(const Run& result) {
auto& Out = GetOutputStream(); auto& Out = GetOutputStream();
auto name_color = (result.report_big_o || result.report_rms) auto name_color =
? COLOR_BLUE : COLOR_GREEN; (result.report_big_o || result.report_rms) ? COLOR_BLUE : COLOR_GREEN;
ColorPrintf(Out, name_color, "%-*s ", name_field_width_, ColorPrintf(Out, name_color, "%-*s ", name_field_width_,
result.benchmark_name.c_str()); result.benchmark_name.c_str());
@ -89,20 +89,20 @@ void ConsoleReporter::PrintRunData(const Run& result) {
const double real_time = result.GetAdjustedRealTime(); const double real_time = result.GetAdjustedRealTime();
const double cpu_time = result.GetAdjustedCPUTime(); const double cpu_time = result.GetAdjustedCPUTime();
if(result.report_big_o) { if (result.report_big_o) {
std::string big_o = GetBigOString(result.complexity); std::string big_o = GetBigOString(result.complexity);
ColorPrintf(Out, COLOR_YELLOW, "%10.2f %s %10.2f %s ", ColorPrintf(Out, COLOR_YELLOW, "%10.2f %s %10.2f %s ", real_time,
real_time, big_o.c_str(), cpu_time, big_o.c_str()); big_o.c_str(), cpu_time, big_o.c_str());
} else if(result.report_rms) { } else if (result.report_rms) {
ColorPrintf(Out, COLOR_YELLOW, "%10.0f %% %10.0f %% ", ColorPrintf(Out, COLOR_YELLOW, "%10.0f %% %10.0f %% ", real_time * 100,
real_time * 100, cpu_time * 100); cpu_time * 100);
} else { } else {
const char* timeLabel = GetTimeUnitString(result.time_unit); const char* timeLabel = GetTimeUnitString(result.time_unit);
ColorPrintf(Out, COLOR_YELLOW, "%10.0f %s %10.0f %s ", ColorPrintf(Out, COLOR_YELLOW, "%10.0f %s %10.0f %s ", real_time, timeLabel,
real_time, timeLabel, cpu_time, timeLabel); cpu_time, timeLabel);
} }
if(!result.report_big_o && !result.report_rms) { if (!result.report_big_o && !result.report_rms) {
ColorPrintf(Out, COLOR_CYAN, "%10lld", result.iterations); ColorPrintf(Out, COLOR_CYAN, "%10lld", result.iterations);
} }

View file

@ -15,8 +15,8 @@
#include "benchmark/reporter.h" #include "benchmark/reporter.h"
#include "complexity.h" #include "complexity.h"
#include <cstdint>
#include <algorithm> #include <algorithm>
#include <cstdint>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <tuple> #include <tuple>
@ -80,7 +80,7 @@ void CSVReporter::PrintRunData(const Run & run) {
} }
// Do not print iteration on bigO and RMS report // Do not print iteration on bigO and RMS report
if(!run.report_big_o && !run.report_rms) { if (!run.report_big_o && !run.report_rms) {
Out << run.iterations; Out << run.iterations;
} }
Out << ","; Out << ",";
@ -89,9 +89,9 @@ void CSVReporter::PrintRunData(const Run & run) {
Out << run.GetAdjustedCPUTime() << ","; Out << run.GetAdjustedCPUTime() << ",";
// Do not print timeLabel on bigO and RMS report // Do not print timeLabel on bigO and RMS report
if(run.report_big_o) { if (run.report_big_o) {
Out << GetBigOString(run.complexity); Out << GetBigOString(run.complexity);
} else if(!run.report_rms){ } else if (!run.report_rms) {
Out << GetTimeUnitString(run.time_unit); Out << GetTimeUnitString(run.time_unit);
} }
Out << ","; Out << ",";

View file

@ -15,8 +15,8 @@
#include "benchmark/reporter.h" #include "benchmark/reporter.h"
#include "complexity.h" #include "complexity.h"
#include <cstdint>
#include <algorithm> #include <algorithm>
#include <cstdint>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <tuple> #include <tuple>
@ -129,7 +129,7 @@ void JSONReporter::PrintRunData(Run const& run) {
<< FormatKV("error_message", run.error_message) << FormatKV("error_message", run.error_message)
<< ",\n"; << ",\n";
} }
if(!run.report_big_o && !run.report_rms) { if (!run.report_big_o && !run.report_rms) {
out << indent out << indent
<< FormatKV("iterations", run.iterations) << FormatKV("iterations", run.iterations)
<< ",\n"; << ",\n";
@ -140,7 +140,7 @@ void JSONReporter::PrintRunData(Run const& run) {
<< FormatKV("cpu_time", RoundDouble(run.GetAdjustedCPUTime())); << FormatKV("cpu_time", RoundDouble(run.GetAdjustedCPUTime()));
out << ",\n" << indent out << ",\n" << indent
<< FormatKV("time_unit", GetTimeUnitString(run.time_unit)); << FormatKV("time_unit", GetTimeUnitString(run.time_unit));
} else if(run.report_big_o) { } else if (run.report_big_o) {
out << indent out << indent
<< FormatKV("cpu_coefficient", RoundDouble(run.GetAdjustedCPUTime())) << FormatKV("cpu_coefficient", RoundDouble(run.GetAdjustedCPUTime()))
<< ",\n"; << ",\n";
@ -158,15 +158,18 @@ void JSONReporter::PrintRunData(Run const& run) {
<< '%'; << '%';
} }
if (run.bytes_per_second > 0.0) { if (run.bytes_per_second > 0.0) {
out << ",\n" << indent out << ",\n"
<< indent
<< FormatKV("bytes_per_second", RoundDouble(run.bytes_per_second)); << FormatKV("bytes_per_second", RoundDouble(run.bytes_per_second));
} }
if (run.items_per_second > 0.0) { if (run.items_per_second > 0.0) {
out << ",\n" << indent out << ",\n"
<< indent
<< FormatKV("items_per_second", RoundDouble(run.items_per_second)); << FormatKV("items_per_second", RoundDouble(run.items_per_second));
} }
if (!run.report_label.empty()) { if (!run.report_label.empty()) {
out << ",\n" << indent out << ",\n"
<< indent
<< FormatKV("label", run.report_label); << FormatKV("label", run.report_label);
} }
out << '\n'; out << '\n';