[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
WindowsFAQ » handle » CppArray » constant » motherboard » games » assembly » microprocessor » CppVclSendEmail » CppGraphics » PerformanceTimers

Performance Timers

While not present on every single system, I have yet to find a computer that does not have performance timers. If you have ever run into problems with the windows timers being too slow, then performance timers may solve your problem. Windows timing messages, as well as most functions that retrieve time, usually have resolutions of 40-50 ms, which is unacceptable for many applications. Programs that use the video hardware can use vertical retrace synchronization, but even this is not always available.

Performance timers are interfaced with two windows functions: BOOL QueryPerformanceFrequency(LARGE_INTEGER *lpFrequency); BOOL QueryPerformanceCounter(LARGE_INTEGER *lpPerformanceCount);

By dividing the value returned with QueryPerformanceCounter by the value returned with QueryPerformanceFrequency, you can measure seconds (or any fraction thereof). For example:

QueryPerformanceFrequency(frequency);
QueryPerformanceCounter(start); // Start
...
QueryPerformanceCounter(end); // End


At this point, (end-start)/frequency = time in seconds between start and end.

last edited (December 14, 2002) by Doctor Slush, Number of views: 4388, Current Rev: 1

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Site Management by Lars Hagelin at Kontantkort.se.