Unverified Commit c4858d80 by Dominic Hamon Committed by GitHub

Report the actual iterations run. (#572)

Before this change, we would report the number of requested iterations passed to the state. After, we will report the actual number run. As a side-effect, instead of multiplying the expected iterations by the number of threads to get the total number, we can report the actual number of iterations across all threads, which takes into account the situation where some threads might run more iterations than others.
parent 64e5a13f
...@@ -115,7 +115,7 @@ namespace { ...@@ -115,7 +115,7 @@ namespace {
BenchmarkReporter::Run CreateRunReport( BenchmarkReporter::Run CreateRunReport(
const benchmark::internal::Benchmark::Instance& b, const benchmark::internal::Benchmark::Instance& b,
const internal::ThreadManager::Result& results, size_t iters, const internal::ThreadManager::Result& results,
double seconds) { double seconds) {
// Create report about this benchmark run. // Create report about this benchmark run.
BenchmarkReporter::Run report; BenchmarkReporter::Run report;
...@@ -124,8 +124,8 @@ BenchmarkReporter::Run CreateRunReport( ...@@ -124,8 +124,8 @@ BenchmarkReporter::Run CreateRunReport(
report.error_occurred = results.has_error_; report.error_occurred = results.has_error_;
report.error_message = results.error_message_; report.error_message = results.error_message_;
report.report_label = results.report_label_; report.report_label = results.report_label_;
// Report the total iterations across all threads. // This is the total iterations across all threads.
report.iterations = static_cast<int64_t>(iters) * b.threads; report.iterations = results.iterations;
report.time_unit = b.time_unit; report.time_unit = b.time_unit;
if (!report.error_occurred) { if (!report.error_occurred) {
...@@ -169,6 +169,7 @@ void RunInThread(const benchmark::internal::Benchmark::Instance* b, ...@@ -169,6 +169,7 @@ void RunInThread(const benchmark::internal::Benchmark::Instance* b,
{ {
MutexLock l(manager->GetBenchmarkMutex()); MutexLock l(manager->GetBenchmarkMutex());
internal::ThreadManager::Result& results = manager->results; internal::ThreadManager::Result& results = manager->results;
results.iterations += st.iterations();
results.cpu_time_used += timer.cpu_time_used(); results.cpu_time_used += timer.cpu_time_used();
results.real_time_used += timer.real_time_used(); results.real_time_used += timer.real_time_used();
results.manual_time_used += timer.manual_time_used(); results.manual_time_used += timer.manual_time_used();
...@@ -236,18 +237,17 @@ std::vector<BenchmarkReporter::Run> RunBenchmark( ...@@ -236,18 +237,17 @@ std::vector<BenchmarkReporter::Run> RunBenchmark(
// Determine if this run should be reported; Either it has // Determine if this run should be reported; Either it has
// run for a sufficient amount of time or because an error was reported. // run for a sufficient amount of time or because an error was reported.
const bool should_report = repetition_num > 0 const bool should_report = repetition_num > 0
|| has_explicit_iteration_count // An exact iteration count was requested || has_explicit_iteration_count // An exact iteration count was requested
|| results.has_error_ || results.has_error_
|| iters >= kMaxIterations || iters >= kMaxIterations // No chance to try again, we hit the limit.
|| seconds >= min_time // the elapsed time is large enough || seconds >= min_time // the elapsed time is large enough
// CPU time is specified but the elapsed real time greatly exceeds the // CPU time is specified but the elapsed real time greatly exceeds the
// minimum time. Note that user provided timers are except from this // minimum time. Note that user provided timers are except from this
// sanity check. // sanity check.
|| ((results.real_time_used >= 5 * min_time) && !b.use_manual_time); || ((results.real_time_used >= 5 * min_time) && !b.use_manual_time);
if (should_report) { if (should_report) {
BenchmarkReporter::Run report = BenchmarkReporter::Run report = CreateRunReport(b, results, seconds);
CreateRunReport(b, results, iters, seconds);
if (!report.error_occurred && b.complexity != oNone) if (!report.error_occurred && b.complexity != oNone)
complexity_reports->push_back(report); complexity_reports->push_back(report);
reports.push_back(report); reports.push_back(report);
......
#ifndef BENCHMARK_THREAD_MANAGER_H #ifndef BENCHMARK_THREAD_MANAGER_H
#define BENCHMARK_THREAD_MANAGER_H #define BENCHMARK_THREAD_MANAGER_H
#include <atomic>
#include "benchmark/benchmark.h"
#include "mutex.h" #include "mutex.h"
namespace benchmark { namespace benchmark {
...@@ -35,6 +38,7 @@ class ThreadManager { ...@@ -35,6 +38,7 @@ class ThreadManager {
public: public:
struct Result { struct Result {
int64_t iterations = 0;
double real_time_used = 0; double real_time_used = 0;
double cpu_time_used = 0; double cpu_time_used = 0;
double manual_time_used = 0; double manual_time_used = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment