
Function Timing Simple Question
A value in milliseconds does not mean the timer is running at the millisecond level. For
example, NT has timer resolution of 10ms (uniprocessor) or 15 ms (multiprocessor), and the
MS-DOS systems have timer resolution of 55ms. So the difference between two readings will
either be 0 or be a multiple of the timer resolution, which is far too coarse for most
high-performance timings. Never be misled by confusing the published resolution with the
practical resolution (for example, there are time-related APIs that use 64-bit values in
100ns units, but there is no guarantee that any system in the forseeable future will give
a count interval of 1 between two calls, or cause your thread to be scheduled to an
accuracy of 100ns). For example, I took the example under _ftime, fixed the bug in in (use
%03u instead of %hu), and added a test to print out only when the millitm field changes,
and I get results like
The time is Tue May 21 02:03:21.714 2002
The time is Tue May 21 02:03.21.724 2002
The time is Tue May 21 02:03.21.734 2002
...
The time is Tue May 21 02:03:22.094 2002
The time is Tue May 21 02:03:22.105 2002
The time is Tue May 21 02:03:22.115 2002
joe
Quote:
>Joe,
>I've been using calls to _ftime to fill _timeb structures before and
>after the code in question and then comparing the structures to get
>the elapsed time (in milliseconds). This *seems* to work OK. Is there
>a problem with _ftime?
>Bert
>>Not only are the responses about QueryPerformanceCounter correct, they are the *only* way
>>to get the information you want.
>> joe
>>>Hi,
>>>Can anyone please provide some code as to how I would stopwatch a call to a
>>>function in milliseconds in MFC?
>>>For example
>>>Init Timer
>>>Call Function
>>>End Timer
>>>MessageBox(Time Elapsed)
>>Joseph M. Newcomer [MVP]
>>Web: http://www3.pgh.net/~newcomer
>>MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm
Joseph M. Newcomer [MVP]
Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm