summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsnappy.mirrorbot@gmail.com <snappy.mirrorbot@gmail.com@03e5f5b5-db94-4691-08a0-1a8bf15f6143>2012-07-04 09:34:48 +0000
committersnappy.mirrorbot@gmail.com <snappy.mirrorbot@gmail.com@03e5f5b5-db94-4691-08a0-1a8bf15f6143>2012-07-04 09:34:48 +0000
commite89f20ab46ee11050760c6d57f05c2a3825a911c (patch)
tree6def3f928b48b4d3d8ade7e9aa857157c6ab025a
parent3ec60ac9878de5d0317ad38fc545080a4bfaa74f (diff)
downloadsnappy-git-e89f20ab46ee11050760c6d57f05c2a3825a911c.tar.gz
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
-rw-r--r--snappy-test.cc33
1 files changed, 19 insertions, 14 deletions
diff --git a/snappy-test.cc b/snappy-test.cc
index 223cd92..6a0611e 100644
--- a/snappy-test.cc
+++ b/snappy-test.cc
@@ -204,27 +204,32 @@ 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 (bytes_per_second < 1024) {
- human_readable_speed = StringPrintf("%dB/s", bytes_per_second);
- } else if (bytes_per_second < 1024 * 1024) {
- human_readable_speed = StringPrintf(
- "%.1fkB/s", bytes_per_second / 1024.0f);
- } else if (bytes_per_second < 1024 * 1024 * 1024) {
- human_readable_speed = StringPrintf(
- "%.1fMB/s", bytes_per_second / (1024.0f * 1024.0f));
+ if (cpu_time_us <= 0) {
+ human_readable_speed = "?";
} else {
- human_readable_speed = StringPrintf(
- "%.1fGB/s", bytes_per_second / (1024.0f * 1024.0f * 1024.0f));
+ 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) {
+ human_readable_speed = StringPrintf(
+ "%.1fkB/s", bytes_per_second / 1024.0f);
+ } else if (bytes_per_second < 1024 * 1024 * 1024) {
+ human_readable_speed = StringPrintf(
+ "%.1fMB/s", bytes_per_second / (1024.0f * 1024.0f));
+ } else {
+ human_readable_speed = StringPrintf(
+ "%.1fGB/s", bytes_per_second / (1024.0f * 1024.0f * 1024.0f));
+ }
}
fprintf(stderr,