I'm having concerns about the accuracy of clock(). It may not have enough resolution to do adequate timings in some cases even for a bot. I'll report what I find here once I'm done testing.
BTW to test the
ProcessTime function, you don't have to wait 28 days for a rollover, instead create a function called clock_test() and replace clock() with it as shown here
Code:
long clock_test(void)
{
static long counter = LONG_MAX-2; // set this to rollover in 2 clock ticks;
counter++;
if (counter < 0) counter = 0; // reset to zero on rollover;
return counter;
}
Now run a simulted timing test to see if
ProcessTime deals with the rollover properly.
Code:
start = ProcessTime(); // clock_test()= LONG_MAX-1
stop = ProcessTime(); // clock_test()= LONG_MAX
diff = stop - start; // diff should = 0.001 seconds
stop = ProcessTime(); // clock_test()= 0 due to rollover
diff = stop - start; // diff should = 0.002 seconds
*update*
On my computer, tests show that clock() increments in units of 10 ticks. This means the actual resolution is in units of 0.01 second instead of 0.001 second. You can still time events which take more time than 1/100th of a second, but there are many timing applications where you'll need more resolution. For example, you cannot use clock() to accurately time the duration of frames (100 FPS = 0.01 seconds per frame which is at the resolution limit).