mirror of
https://github.com/google/benchmark.git
synced 2024-12-03 14:53:19 +00:00
google formated
This commit is contained in:
parent
109f528a40
commit
22cb9d9ce0
|
@ -20,7 +20,7 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "benchmark_api.h" // For forward declaration of BenchmarkReporter
|
#include "benchmark_api.h" // For forward declaration of BenchmarkReporter
|
||||||
|
|
||||||
namespace benchmark {
|
namespace benchmark {
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ class BenchmarkReporter {
|
||||||
error_stream_ = err;
|
error_stream_ = err;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& GetOutputStream() const {
|
std::ostream& GetOutputStream() const {
|
||||||
return *output_stream_;
|
return *output_stream_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,61 +156,61 @@ 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);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const char* GetTimeUnitString(TimeUnit unit) {
|
inline const char* GetTimeUnitString(TimeUnit unit) {
|
||||||
switch (unit) {
|
switch (unit) {
|
||||||
case kMillisecond:
|
case kMillisecond:
|
||||||
return "ms";
|
return "ms";
|
||||||
case kMicrosecond:
|
case kMicrosecond:
|
||||||
return "us";
|
return "us";
|
||||||
case kNanosecond:
|
case kNanosecond:
|
||||||
default:
|
default:
|
||||||
return "ns";
|
return "ns";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline double GetTimeUnitMultiplier(TimeUnit unit) {
|
inline double GetTimeUnitMultiplier(TimeUnit unit) {
|
||||||
switch (unit) {
|
switch (unit) {
|
||||||
case kMillisecond:
|
case kMillisecond:
|
||||||
return 1e3;
|
return 1e3;
|
||||||
case kMicrosecond:
|
case kMicrosecond:
|
||||||
return 1e6;
|
return 1e6;
|
||||||
case kNanosecond:
|
case kNanosecond:
|
||||||
default:
|
default:
|
||||||
return 1e9;
|
return 1e9;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace benchmark
|
} // end namespace benchmark
|
||||||
#endif // BENCHMARK_REPORTER_H_
|
#endif // BENCHMARK_REPORTER_H_
|
||||||
|
|
|
@ -17,50 +17,50 @@
|
||||||
|
|
||||||
#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 {
|
||||||
|
|
||||||
// Internal function to calculate the different scalability forms
|
// Internal function to calculate the different scalability forms
|
||||||
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; };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to return an string for the calculated complexity
|
// Function to return an string for the calculated complexity
|
||||||
std::string GetBigOString(BigO complexity) {
|
std::string GetBigOString(BigO complexity) {
|
||||||
switch (complexity) {
|
switch (complexity) {
|
||||||
case oN:
|
case oN:
|
||||||
return "N";
|
return "N";
|
||||||
case oNSquared:
|
case oNSquared:
|
||||||
return "N^2";
|
return "N^2";
|
||||||
case oNCubed:
|
case oNCubed:
|
||||||
return "N^3";
|
return "N^3";
|
||||||
case oLogN:
|
case oLogN:
|
||||||
return "lgN";
|
return "lgN";
|
||||||
case oNLogN:
|
case oNLogN:
|
||||||
return "NlgN";
|
return "NlgN";
|
||||||
case o1:
|
case o1:
|
||||||
return "(1)";
|
return "(1)";
|
||||||
default:
|
default:
|
||||||
return "f(N)";
|
return "f(N)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
|
|
@ -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());
|
||||||
|
|
||||||
|
@ -84,25 +84,25 @@ void ConsoleReporter::PrintRunData(const Run& result) {
|
||||||
if (result.items_per_second > 0) {
|
if (result.items_per_second > 0) {
|
||||||
items = StrCat(" ", HumanReadableNumber(result.items_per_second),
|
items = StrCat(" ", HumanReadableNumber(result.items_per_second),
|
||||||
" items/s");
|
" items/s");
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 << ",";
|
||||||
|
@ -111,7 +111,7 @@ void CSVReporter::PrintRunData(const Run & run) {
|
||||||
ReplaceAll(&label, "\"", "\"\"");
|
ReplaceAll(&label, "\"", "\"\"");
|
||||||
Out << "\"" << label << "\"";
|
Out << "\"" << label << "\"";
|
||||||
}
|
}
|
||||||
Out << ",,"; // for error_occurred and error_message
|
Out << ",,"; // for error_occurred and error_message
|
||||||
Out << '\n';
|
Out << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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>
|
||||||
|
@ -100,24 +100,24 @@ void JSONReporter::ReportRuns(std::vector<Run> const& reports) {
|
||||||
first_report_ = false;
|
first_report_ = false;
|
||||||
|
|
||||||
for (auto it = reports.begin(); it != reports.end(); ++it) {
|
for (auto it = reports.begin(); it != reports.end(); ++it) {
|
||||||
out << indent << "{\n";
|
out << indent << "{\n";
|
||||||
PrintRunData(*it);
|
PrintRunData(*it);
|
||||||
out << indent << '}';
|
out << indent << '}';
|
||||||
auto it_cp = it;
|
auto it_cp = it;
|
||||||
if (++it_cp != reports.end()) {
|
if (++it_cp != reports.end()) {
|
||||||
out << ",\n";
|
out << ",\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JSONReporter::Finalize() {
|
void JSONReporter::Finalize() {
|
||||||
// Close the list of benchmarks and the top level object.
|
// Close the list of benchmarks and the top level object.
|
||||||
GetOutputStream() << "\n ]\n}\n";
|
GetOutputStream() << "\n ]\n}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void JSONReporter::PrintRunData(Run const& run) {
|
void JSONReporter::PrintRunData(Run const& run) {
|
||||||
std::string indent(6, ' ');
|
std::string indent(6, ' ');
|
||||||
std::ostream& out = GetOutputStream();
|
std::ostream& out = GetOutputStream();
|
||||||
out << indent
|
out << indent
|
||||||
<< FormatKV("name", run.benchmark_name)
|
<< FormatKV("name", run.benchmark_name)
|
||||||
<< ",\n";
|
<< ",\n";
|
||||||
|
@ -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,14 +140,14 @@ 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";
|
||||||
out << indent
|
out << indent
|
||||||
<< FormatKV("real_coefficient", RoundDouble(run.GetAdjustedRealTime()))
|
<< FormatKV("real_coefficient", RoundDouble(run.GetAdjustedRealTime()))
|
||||||
<< ",\n";
|
<< ",\n";
|
||||||
out << indent
|
out << indent
|
||||||
<< FormatKV("big_o", GetBigOString(run.complexity))
|
<< FormatKV("big_o", GetBigOString(run.complexity))
|
||||||
<< ",\n";
|
<< ",\n";
|
||||||
out << indent
|
out << indent
|
||||||
|
@ -156,20 +156,23 @@ void JSONReporter::PrintRunData(Run const& run) {
|
||||||
out << indent
|
out << indent
|
||||||
<< FormatKV("rms", RoundDouble(run.GetAdjustedCPUTime()*100))
|
<< FormatKV("rms", RoundDouble(run.GetAdjustedCPUTime()*100))
|
||||||
<< '%';
|
<< '%';
|
||||||
}
|
}
|
||||||
if (run.bytes_per_second > 0.0) {
|
if (run.bytes_per_second > 0.0) {
|
||||||
out << ",\n" << indent
|
out << ",\n"
|
||||||
<< FormatKV("bytes_per_second", RoundDouble(run.bytes_per_second));
|
<< indent
|
||||||
}
|
<< FormatKV("bytes_per_second", RoundDouble(run.bytes_per_second));
|
||||||
if (run.items_per_second > 0.0) {
|
}
|
||||||
out << ",\n" << indent
|
if (run.items_per_second > 0.0) {
|
||||||
<< FormatKV("items_per_second", RoundDouble(run.items_per_second));
|
out << ",\n"
|
||||||
}
|
<< indent
|
||||||
if (!run.report_label.empty()) {
|
<< FormatKV("items_per_second", RoundDouble(run.items_per_second));
|
||||||
out << ",\n" << indent
|
}
|
||||||
<< FormatKV("label", run.report_label);
|
if (!run.report_label.empty()) {
|
||||||
}
|
out << ",\n"
|
||||||
out << '\n';
|
<< indent
|
||||||
|
<< FormatKV("label", run.report_label);
|
||||||
|
}
|
||||||
|
out << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace benchmark
|
} // end namespace benchmark
|
||||||
|
|
Loading…
Reference in a new issue