diff options
author | snappy.mirrorbot@gmail.com <snappy.mirrorbot@gmail.com@03e5f5b5-db94-4691-08a0-1a8bf15f6143> | 2011-04-26 12:34:55 +0000 |
---|---|---|
committer | snappy.mirrorbot@gmail.com <snappy.mirrorbot@gmail.com@03e5f5b5-db94-4691-08a0-1a8bf15f6143> | 2011-04-26 12:34:55 +0000 |
commit | 0c4abb90f64444a1916e4bca777997e622b378e1 (patch) | |
tree | ee8263044598880e546e1d943835a17feb89df28 /snappy-test.cc | |
parent | 916ff425904853fba909e839d76dfc5dcec4ccc7 (diff) | |
download | snappy-0c4abb90f64444a1916e4bca777997e622b378e1.tar.gz |
Fix public issue #30: Stop using gettimeofday() altogether on Win32,
as MSVC doesn't include it. Replace with QueryPerformanceCounter(),
which is monotonic and probably reasonably high-resolution.
(Some machines have traditionally had bugs in QPC, but they should
be relatively rare these days, and there's really no much better
alternative that I know of.)
R=csilvers
DELTA=74 (55 added, 19 deleted, 0 changed)
Revision created by MOE tool push_codebase.
MOE_MIGRATION=1556
git-svn-id: http://snappy.googlecode.com/svn/trunk@31 03e5f5b5-db94-4691-08a0-1a8bf15f6143
Diffstat (limited to 'snappy-test.cc')
-rw-r--r-- | snappy-test.cc | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/snappy-test.cc b/snappy-test.cc index b608516..c9aae2e 100644 --- a/snappy-test.cc +++ b/snappy-test.cc @@ -74,21 +74,22 @@ void ResetBenchmarkTiming() { benchmark_cpu_time_us = 0; } -struct timeval benchmark_start_real; - #ifdef WIN32 +LARGE_INTEGER benchmark_start_real; FILETIME benchmark_start_cpu; #else // WIN32 +struct timeval benchmark_start_real; struct rusage benchmark_start_cpu; #endif // WIN32 void StartBenchmarkTiming() { - gettimeofday(&benchmark_start_real, NULL); #ifdef WIN32 + QueryPerformanceCounter(&benchmark_start_real); FILETIME dummy; CHECK(GetProcessTimes( GetCurrentProcess(), &dummy, &dummy, &dummy, &benchmark_start_cpu)); #else + gettimeofday(&benchmark_start_real, NULL); if (getrusage(RUSAGE_SELF, &benchmark_start_cpu) == -1) { perror("getrusage(RUSAGE_SELF)"); exit(1); @@ -101,14 +102,18 @@ void StopBenchmarkTiming() { if (!benchmark_running) { return; } - struct timeval benchmark_stop_real; - gettimeofday(&benchmark_stop_real, NULL); - benchmark_real_time_us += - 1000000 * (benchmark_stop_real.tv_sec - benchmark_start_real.tv_sec); - benchmark_real_time_us += - (benchmark_stop_real.tv_usec - benchmark_start_real.tv_usec); #ifdef WIN32 + LARGE_INTEGER benchmark_stop_real; + LARGE_INTEGER benchmark_frequency; + QueryPerformanceCounter(&benchmark_stop_real); + QueryPerformanceFrequency(&benchmark_frequency); + + double elapsed_real = static_cast<double>( + benchmark_stop_real.QuadPart - benchmark_start_real.QuadPart) / + benchmark_frequency.QuadPart; + benchmark_real_time_us += elapsed_real * 1e6 + 0.5; + FILETIME benchmark_stop_cpu, dummy; CHECK(GetProcessTimes( GetCurrentProcess(), &dummy, &dummy, &dummy, &benchmark_stop_cpu)); @@ -124,6 +129,13 @@ void StopBenchmarkTiming() { benchmark_cpu_time_us += (stop_ulargeint.QuadPart - start_ulargeint.QuadPart + 5) / 10; #else // WIN32 + struct timeval benchmark_stop_real; + gettimeofday(&benchmark_stop_real, NULL); + benchmark_real_time_us += + 1000000 * (benchmark_stop_real.tv_sec - benchmark_start_real.tv_sec); + benchmark_real_time_us += + (benchmark_stop_real.tv_usec - benchmark_start_real.tv_usec); + struct rusage benchmark_stop_cpu; if (getrusage(RUSAGE_SELF, &benchmark_stop_cpu) == -1) { perror("getrusage(RUSAGE_SELF)"); |