New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Windows resolution problems by replacing Data.Time.Clock.POSIX with System.Clock #24
Comments
I'm using Windows 7 64-bit. With this patch I see a similar improvement. |
What's the status of this? Is unpatched criterion good for benchmarking on Windows by now? |
Thanks, I've fixed this in 53d3203. The fix is fairly involved because it needs to work on multiple platforms. I particularly commend you to read the comment at the start of the Windows file. |
Thanks for the update. I'll use criterion within Windows more often, and see how this improves time measurements. It looks like the At first I thought calling According to a comment on |
I still see this bug with criterion-0.8.0.1. Is the patch not yet in the latest released version? |
There is not a release that has this fix. You'll want to use HEAD for a bit if you need it. |
Ok, thanks. |
On Windows, getPOSIXTime uses the C function
GetSystemTimeAsFileTime
, which gives low-resolution timings. As observed in issue #11, it will return the same value many times in a row.criterion
therefore produces low-quality statistics under Windows.QueryPerformanceCounter
is the appropriate timing source for benchmarks on Windows; we can access it withClock.getTime Clock.Monotonic
from theclock
package. See example data below.My patch, conklech/criterion@b6f657c, fixes the problem on Windows, but might create compatibility problems on some POSIX systems.
In issue #2, @coreyoconnor gave a similar patch, coreyoconnor/criterion@37b1216, which uses
Clock.ProcessCPUTime
instead. That has different semantics--which was the goal there. But it's not clear thatClock.ProcessCPUTime
gives benchmark-grade data on Windows. It usesGetProcessTimes
under the hood; MSDN doesn't explain where the data comes from, and I haven't tested it.Under POSIX,
time
callsgettimeofday
andclock
callsclock_gettime
. Cursory Google research indicates thatclock_gettime
withCLOCK_MONOTONIC
is the proper benchmark timesource;gettimeofday
can go backwards, for instance whenntp
is adjusting the clock.However, it looks like some systems don't implement
CLOCK_MONOTONIC
. Perhaps just OS X? I don't know. Someone with better POSIX knowledge should look into compatibility issues withCLOCK_MONOTONIC
in non-Win32 environments.On my Windows 7 laptop,
criterion
usingtime
(i.e.criterion-0.6.2.1
) reports an estimated resolution of about 3.2 msec, with the weird 200% outlier rate reported by others. However, the final report data shows that all measurements share the same two or three values:After dropping in
clock
and usingClock.Monotonic
, the resolution is reported as 4.5 msec but the outlier rate problem is gone, and the final report shows an actual distribution of data:The text was updated successfully, but these errors were encountered: