1
0
mirror of https://github.com/google/benchmark.git synced 2025-04-12 20:41:14 +08:00

change how trial iteration counts are increased in an attempt to save time

This commit is contained in:
Eric Fiselier 2015-02-18 20:05:38 -05:00
parent 0c9cfe4637
commit 7aea5d74a3
2 changed files with 9 additions and 5 deletions

View File

@ -68,7 +68,7 @@ DEFINE_string(benchmarks, "all",
"If this flag is the string \"all\", all benchmarks linked "
"into the process are run.");
DEFINE_int32(benchmark_min_iters, 100,
DEFINE_int32(benchmark_min_iters, 1,
"Minimum number of iterations per benchmark");
DEFINE_int32(benchmark_max_iters, 1000000000,
@ -670,9 +670,13 @@ void RunBenchmark(const benchmark::Benchmark::Instance& b,
// See how much iterations should be increased by
// Note: Avoid division by zero with max(seconds, 1ns).
double multiplier = 1.4 * FLAGS_benchmark_min_time /
std::max(seconds, 1e-9);
multiplier = std::min(10.0, multiplier); // At most 10 times expansion
double multiplier = FLAGS_benchmark_min_time * 1.4 / std::max(seconds, 1e-9);
// If our last run was at least 10% of FLAGS_benchmark_min_time then we
// use the multiplier directly. Otherwise we use at most 10 times
// expansion.
bool is_significant = (seconds / FLAGS_benchmark_min_time) > 0.1;
multiplier = is_significant ? multiplier : std::min(10.0, multiplier);
// TODO(ericwf) I don't think this branch is reachable.
if (multiplier <= 1.0) multiplier = 2.0;
double next_iters = std::max(multiplier * iters, iters + 1.0);
if (next_iters > FLAGS_benchmark_max_iters) {

View File

@ -171,7 +171,7 @@ static void BM_LongTest(int iters, int xrange) {
for (int i = 0; i < xrange; ++i)
tracker += i;
}
assert(tracker != 0.0);
assert(tracker > 1.0);
}
BENCHMARK(BM_LongTest)->Range(1<<16,1<<28);