From a1f9f9973d127992f341d442969c86fd9a0847c9 Mon Sep 17 00:00:00 2001 From: "snappy.mirrorbot@gmail.com" Date: Mon, 9 May 2011 21:29:02 +0000 Subject: [PATCH] Fix public issue #39: Pick out the median runs based on CPU time, not real time. Also, use nth_element instead of sort, since we only need one element. R=csilvers DELTA=5 (3 added, 0 deleted, 2 changed) Revision created by MOE tool push_codebase. MOE_MIGRATION=1799 git-svn-id: https://snappy.googlecode.com/svn/trunk@35 03e5f5b5-db94-4691-08a0-1a8bf15f6143 --- snappy-test.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/snappy-test.cc b/snappy-test.cc index 4c8caaf..2c50388 100644 --- a/snappy-test.cc +++ b/snappy-test.cc @@ -168,7 +168,7 @@ struct BenchmarkRun { struct BenchmarkCompareCPUTime { bool operator() (const BenchmarkRun& a, const BenchmarkRun& b) const { - return a.real_time_us < b.real_time_us; + return a.cpu_time_us < b.cpu_time_us; } }; @@ -204,7 +204,10 @@ void Benchmark::Run() { benchmark_runs[run].cpu_time_us = benchmark_cpu_time_us; } - sort(benchmark_runs, benchmark_runs + kNumRuns, BenchmarkCompareCPUTime()); + nth_element(benchmark_runs, + benchmark_runs + kMedianPos, + benchmark_runs + kNumRuns, + BenchmarkCompareCPUTime()); int64 real_time_us = benchmark_runs[kMedianPos].real_time_us; int64 cpu_time_us = benchmark_runs[kMedianPos].cpu_time_us; int64 bytes_per_second = benchmark_bytes_processed * 1000000 / cpu_time_us;