By registering with us, you'll be able to discuss, share and exchange private messages with other members of our community.

SignUp Now!

Time of day with microseconds?

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.

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
... Profiling a batch file?
Hmmm! I don't know. To take advantage of the higher precision, you'd need an enormous amount of data.
You can already measure intervals (enough for profiling) with microsecond precision with 4UTILS's @CLOCK, which (IMHO) has the best format for that purpose.
v:\> clock 1 zon & do i=1 to 5 ( echo %@clock[1,s]    %_mutime    %_muage )
0.000593    12:24:22.003097    130478270620031589
0.001804    12:24:22.004282    130478270620043291
0.002857    12:24:22.005370    130478270620054232
0.003983    12:24:22.006472    130478270620065284
0.005092    12:24:22.007578    130478270620076421

What do you suppose is the closest command to "do nothing" in TCC? Such would be useful in determining the overhead of TCC's looping mechanisms. Would NOOP, _NOOP, and @NOOP be useful? ... all with the same minimal definition, {return 0;}.