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

@ -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 {
@ -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,13 +152,12 @@ 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) {
@ -178,8 +177,7 @@ 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 +=
@ -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;
@ -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());
@ -91,15 +91,15 @@ void ConsoleReporter::PrintRunData(const Run& result) {
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) {

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>

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>
@ -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';