1
0
mirror of https://github.com/google/benchmark.git synced 2025-04-29 06:20:32 +08:00

Add more context information and print estimated runtime

This commit is contained in:
Eric Fiselier 2015-03-19 11:40:17 -04:00
parent 8b0b73f06c
commit a6268f184b
3 changed files with 18 additions and 0 deletions

View File

@ -34,6 +34,9 @@ class BenchmarkReporter {
double mhz_per_cpu;
bool cpu_scaling_enabled;
double benchmark_min_time;
size_t benchmark_count;
size_t benchmark_repetitions;
// The number of chars in the longest benchmark name.
size_t name_field_width;
};

View File

@ -802,8 +802,13 @@ void RunMatchingBenchmarks(const std::string& spec,
context.mhz_per_cpu = CyclesPerSecond() / 1000000.0f;
context.cpu_scaling_enabled = CpuScalingEnabled();
context.benchmark_count = benchmarks.size();
context.benchmark_min_time = FLAGS_benchmark_iterations ? 0.0
: FLAGS_benchmark_min_time;
context.benchmark_repetitions = FLAGS_benchmark_repetitions;
context.name_field_width = name_field_width;
if (reporter->ReportContext(context)) {
for (const auto& benchmark : benchmarks) {
RunBenchmark(benchmark, reporter);

View File

@ -14,9 +14,11 @@
#include "benchmark/reporter.h"
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <limits>
#include <string>
#include <vector>
@ -113,6 +115,14 @@ bool ConsoleReporter::ReportContext(const Context& context) {
#ifndef NDEBUG
fprintf(stdout, "Build Type: DEBUG\n");
#endif
if (std::abs(context.benchmark_min_time)
> std::numeric_limits<double>::epsilon()) {
double estimated_time = context.benchmark_count
* context.benchmark_repetitions
* context.benchmark_min_time
* 1.4;
fprintf(stdout, "Estimated run time: %.0fs\n", estimated_time);
}
int output_width =
fprintf(stdout,