Skip to content

Commit

Permalink
Fix public issue google#39: Pick out the median runs based on CPU time,
Browse files Browse the repository at this point in the history
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
  • Loading branch information
[email protected] committed May 9, 2011
1 parent f7b1056 commit a1f9f99
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions snappy-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a1f9f99

Please sign in to comment.