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
This commit is contained in:
snappy.mirrorbot@gmail.com 2011-05-09 21:29:02 +00:00
parent f7b105683c
commit a1f9f9973d

View file

@ -168,7 +168,7 @@ struct BenchmarkRun {
struct BenchmarkCompareCPUTime { struct BenchmarkCompareCPUTime {
bool operator() (const BenchmarkRun& a, const BenchmarkRun& b) const { 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; 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 real_time_us = benchmark_runs[kMedianPos].real_time_us;
int64 cpu_time_us = benchmark_runs[kMedianPos].cpu_time_us; int64 cpu_time_us = benchmark_runs[kMedianPos].cpu_time_us;
int64 bytes_per_second = benchmark_bytes_processed * 1000000 / cpu_time_us; int64 bytes_per_second = benchmark_bytes_processed * 1000000 / cpu_time_us;