- May
- 13,117
- 180
Yesterday I read that Win8 has GetSystemTimePreciseAsFileTime() which has microsecond precision. An article I read suggests it has about 35 mu-s accuracy. The article also described it (vaguely) as a combination of QueryPerformanceCounter() and GetSystemTimeAsFileTime(). I suppose it must be similar to a technique I used in my 4THREADS plugin (WATCHDIR) in 2009, namely, periodically synchronize the system time with the performance counter by recording matching "marks" in time and adjust SYSTEMTIMEs (actually FILETIMEs, typically 10 or 15 millisecond precision) using the performance counter to extrapolate greater precision. I wonder if Win8 actually uses this in creating timestamps for files.
I spent a couple days putting it into a plugin and trying to figure out why it got a little inaccurate when the processor was being pushed. I tried all priorities short of REALTIME, a strategy which didn't work. In the end the solution was a matter of calling timeBeginPeriod() using the maximum resolution to get the synchronization timer more accurate under heavy CPU use.
The test plugin works well (example below) but I can't think of a use for it. Does anyone have a use for times of day (or AGEs) with microsecond precision? Looking at my example, I realize I didn't truncate (or round) the AGEs to mu-secs, so they have .1 mu-sec precision. Right now the plugin is called "DumbDir" (thanks, Charles) because that was the first thing I found that was simple enough to turn into a new plugin quickly. If it seems useful, it may wind up in 4UTILS.
I spent a couple days putting it into a plugin and trying to figure out why it got a little inaccurate when the processor was being pushed. I tried all priorities short of REALTIME, a strategy which didn't work. In the end the solution was a matter of calling timeBeginPeriod() using the maximum resolution to get the synchronization timer more accurate under heavy CPU use.
The test plugin works well (example below) but I can't think of a use for it. Does anyone have a use for times of day (or AGEs) with microsecond precision? Looking at my example, I realize I didn't truncate (or round) the AGEs to mu-secs, so they have .1 mu-sec precision. Right now the plugin is called "DumbDir" (thanks, Charles) because that was the first thing I found that was simple enough to turn into a new plugin quickly. If it seems useful, it may wind up in 4UTILS.
Code:
v:\> do i=1 to 5 ( echo %_mutime %_muage )
22:00:07.766811 130477752077668665
22:00:07.767435 130477752077675017
22:00:07.767902 130477752077679675
22:00:07.768327 130477752077683732
22:00:07.768660 130477752077687085