mirror of https://github.com/google/snappy.git
Handle the case where gettimeofday() goes backwards or returns the same value
twice; it could cause division by zero in the unit test framework. (We already had one fix for this in place, but it was incomplete.) This could in theory happen on any system, since there are few guarantees about gettimeofday(), but seems to only happen in practice on GNU/Hurd, where gettimeofday() is cached and only updated ever so often. R=sanjay git-svn-id: https://snappy.googlecode.com/svn/trunk@65 03e5f5b5-db94-4691-08a0-1a8bf15f6143
This commit is contained in:
parent
3ec60ac987
commit
e89f20ab46
|
@ -204,16 +204,20 @@ void Benchmark::Run() {
|
|||
benchmark_runs[run].cpu_time_us = benchmark_cpu_time_us;
|
||||
}
|
||||
|
||||
string heading = StringPrintf("%s/%d", name_.c_str(), test_case_num);
|
||||
string human_readable_speed;
|
||||
|
||||
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;
|
||||
|
||||
string heading = StringPrintf("%s/%d", name_.c_str(), test_case_num);
|
||||
string human_readable_speed;
|
||||
if (cpu_time_us <= 0) {
|
||||
human_readable_speed = "?";
|
||||
} else {
|
||||
int64 bytes_per_second =
|
||||
benchmark_bytes_processed * 1000000 / cpu_time_us;
|
||||
if (bytes_per_second < 1024) {
|
||||
human_readable_speed = StringPrintf("%dB/s", bytes_per_second);
|
||||
} else if (bytes_per_second < 1024 * 1024) {
|
||||
|
@ -226,6 +230,7 @@ void Benchmark::Run() {
|
|||
human_readable_speed = StringPrintf(
|
||||
"%.1fGB/s", bytes_per_second / (1024.0f * 1024.0f * 1024.0f));
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr,
|
||||
#ifdef WIN32
|
||||
|
|
Loading…
Reference in New Issue