bench: introduce -min_time argument

When it is not easily possible to stabilize benchmark machine and code
the argument -min_time can be used to specify a minimum duration
that a benchmark should take. E.g. choose -min_time=1000 if you
are willing to wait about 1 second for each benchmark result.

The default is now set to 10ms instead of 0, which should make runs on
fast machines more stable with negligible slowdown.
This commit is contained in:
Martin Ankerl
2021-09-18 08:38:20 +02:00
parent 9fef832932
commit d3c6f8bfa1
3 changed files with 10 additions and 0 deletions

View File

@@ -61,6 +61,12 @@ void benchmark::BenchRunner::RunAll(const Args& args)
Bench bench;
bench.name(p.first);
if (args.min_time > 0ms) {
// convert to nanos before dividing to reduce rounding errors
std::chrono::nanoseconds min_time_ns = args.min_time;
bench.minEpochTime(min_time_ns / bench.epochs());
}
if (args.asymptote.empty()) {
p.second(bench);
} else {