summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsnappy.mirrorbot@gmail.com <snappy.mirrorbot@gmail.com@03e5f5b5-db94-4691-08a0-1a8bf15f6143>2011-05-09 21:28:45 +0000
committersnappy.mirrorbot@gmail.com <snappy.mirrorbot@gmail.com@03e5f5b5-db94-4691-08a0-1a8bf15f6143>2011-05-09 21:28:45 +0000
commit3a172157f6113b748b37a3bc231af8c39c69210f (patch)
tree21add774cef1b6ae6ff7d6fb05e1806120f71925
parentb62cb9da1b8653b8d262066e1e3ee68fe749f30f (diff)
downloadsnappy-3a172157f6113b748b37a3bc231af8c39c69210f.tar.gz
Fix public issue #38: Make the microbenchmark framework handle
properly cases where gettimeofday() can stand return the same result twice (as sometimes on GNU/Hurd) or go backwards (as when the user adjusts the clock). We avoid a division-by-zero, and put a lower bound on the number of iterations -- the same amount as we use to calibrate. We should probably use CLOCK_MONOTONIC for platforms that support it, to be robust against clock adjustments; we already use Windows' monotonic timers. However, that's for a later changelist. R=csilvers DELTA=7 (5 added, 0 deleted, 2 changed) Revision created by MOE tool push_codebase. MOE_MIGRATION=1798 git-svn-id: http://snappy.googlecode.com/svn/trunk@34 03e5f5b5-db94-4691-08a0-1a8bf15f6143
-rw-r--r--snappy-test.cc9
1 files changed, 7 insertions, 2 deletions
diff --git a/snappy-test.cc b/snappy-test.cc
index c9aae2e..4c8caaf 100644
--- a/snappy-test.cc
+++ b/snappy-test.cc
@@ -182,11 +182,16 @@ void Benchmark::Run() {
(*function_)(kCalibrateIterations, test_case_num);
StopBenchmarkTiming();
- // Let each test case run for about 200ms.
+ // Let each test case run for about 200ms, but at least as many
+ // as we used to calibrate.
// Run five times and pick the median.
const int kNumRuns = 5;
const int kMedianPos = kNumRuns / 2;
- int num_iterations = 200000 * kCalibrateIterations / benchmark_real_time_us;
+ int num_iterations = 0;
+ if (benchmark_real_time_us > 0) {
+ num_iterations = 200000 * kCalibrateIterations / benchmark_real_time_us;
+ }
+ num_iterations = max(num_iterations, kCalibrateIterations);
BenchmarkRun benchmark_runs[kNumRuns];
for (int run = 0; run < kNumRuns; ++run) {