1
0
mirror of https://github.com/google/benchmark.git synced 2025-04-29 06:20:32 +08:00
This commit is contained in:
Eric 2015-03-19 18:05:00 +00:00
commit 25af43c6c6
3 changed files with 56 additions and 0 deletions

View File

@ -30,6 +30,12 @@ namespace benchmark {
class BenchmarkReporter {
public:
struct Context {
Context();
// The total number of benchmarks that will be run
std::size_t benchmark_count;
// Information relating to the CPU.
int num_cpus;
double mhz_per_cpu;
bool cpu_scaling_enabled;
@ -80,8 +86,15 @@ class BenchmarkReporter {
virtual void Finalize();
virtual ~BenchmarkReporter();
protected:
static void ComputeStats(std::vector<Run> const& reports, Run* mean, Run* stddev);
// Information relating to the value of the command line flags.
static std::string const& BenchmarkFilterFlag();
static int BenchmarkIterationsFlag();
static double BenchmarkMinTimeFlag();
static int BenchmarkRepetitionsFlag();
static bool ColorPrintFlag();
};
// Simple reporter that outputs benchmark data to the console. This is the

View File

@ -802,6 +802,7 @@ void RunMatchingBenchmarks(const std::string& spec,
context.mhz_per_cpu = CyclesPerSecond() / 1000000.0f;
context.cpu_scaling_enabled = CpuScalingEnabled();
context.benchmark_count = benchmarks.size();
context.name_field_width = name_field_width;
if (reporter->ReportContext(context)) {

View File

@ -22,12 +22,27 @@
#include "check.h"
#include "colorprint.h"
#include "commandlineflags.h"
#include "stat.h"
#include "string_util.h"
#include "walltime.h"
DECLARE_string(benchmark_filter);
DECLARE_int32(benchmark_iterations);
DECLARE_double(benchmark_min_time);
DECLARE_int32(benchmark_repetitions);
DECLARE_bool(color_print);
namespace benchmark {
BenchmarkReporter::Context::Context()
: benchmark_count(0),
num_cpus(0),
mhz_per_cpu(0.0),
cpu_scaling_enabled(false),
name_field_width(0)
{}
void BenchmarkReporter::ComputeStats(
const std::vector<Run>& reports,
Run* mean_data, Run* stddev_data) {
@ -83,6 +98,26 @@ void BenchmarkReporter::ComputeStats(
stddev_data->items_per_second = items_per_second_stat.StdDev();
}
std::string const& BenchmarkReporter::BenchmarkFilterFlag() {
return FLAGS_benchmark_filter;
}
int BenchmarkReporter::BenchmarkIterationsFlag() {
return FLAGS_benchmark_iterations;
}
double BenchmarkReporter::BenchmarkMinTimeFlag() {
return FLAGS_benchmark_min_time;
}
int BenchmarkReporter::BenchmarkRepetitionsFlag() {
return FLAGS_benchmark_repetitions;
}
bool BenchmarkReporter::ColorPrintFlag() {
return FLAGS_color_print;
}
void BenchmarkReporter::Finalize() {
}
@ -113,6 +148,13 @@ bool ConsoleReporter::ReportContext(const Context& context) {
#ifndef NDEBUG
fprintf(stdout, "Build Type: DEBUG\n");
#endif
if (BenchmarkIterationsFlag() == 0) {
double estimated_time = context.benchmark_count
* BenchmarkRepetitionsFlag()
* BenchmarkMinTimeFlag()
* 1.4;
fprintf(stdout, "Estimated run time: %.0fs\n", estimated_time);
}
int output_width =
fprintf(stdout,