Broken links? Email us! |
16 users have rated this article. result: |
|
4.31 out of 5. |
|
Download source files - 3 Kb
Updated: the class is now thread safe.
High resolution timing is supported in Win32 by the QueryPerformanceCounter
and QueryPerformanceFrequency
API calls. The timer resolution varies with the
processor. Today's high speed processors have a timer resolution of less than a
microsecond. Of course, this is a much better resolution than the GetTickCount
API!
Using the QueryPerformanceCounter
calls directly takes too much typing and
the resulting code is usually hard to read. So, I looked all over the net for a
timer class but I could not find one that suited me. I wrote a simple and
powerful timer class and named it CPerfTimer
. I wrote this a long time ago but I
still have not had the need to update it. Searching the net I could not find a
timer class as simple to use and as useful as CPerfTimer
. Several other
timer classes are available and they vary as to their simplicity and
usefulness. I do not claim that this is the end-all-be-all of timer
classes; but, I hope that someone will find it useful enough to refrain
from taking the time to write yet another timer class.
This class is simple to use. Just declare a variable as type CPerfTimer
,
call Start()
to start timing and call Stop()
to stop timing. You can pause a
timer by calling Stop()
and then you can call Start()
to resume. Retrieve the
elapsed time by calling an Elapsed...()
function. Assignment, addition,
subtraction and comparison are supported. There are a few information calls
available also. All calls except Start
and Stop
can be performed on a timer
without stopping it.
I have not included separate documentation or example application. The
code is fairly well documented and the above paragraph was copied from the
CPerfTimer.h file. Methods for adding, subtracting and comparing CPerfTimers
and
seconds (double) are also included. And, a CPerfTimerT
class that should be
thread safe (no extensive testing has been done). Please inform me if any bugs
are found or you have an idea for an enhancement.
Hint: For improved responsiveness, use Internet Explorer 4 (or above) with Javascript enabled, choose 'Use DHTML' from the View dropdown and hit 'Set Options'. | New thread | Messages 1 to 6 of 6 (Total: 6) | First Prev Next Last |
| | | Author | |
| | Date | |
|
| | | Rob Ottenhoff | 6:01 5 Mar 01 |
| | Anonymous | 12:04 5 Mar 01 |
| | | Dean | 17:15 27 Jan 01 |
| | | kabir | 6:37 5 Sep 00 |
| | | Dean Wyant | 4:44 15 Apr 00 |
| | Chris Maunder | 4:50 15 Apr 00 |
|
| Last Visit: 12:00 Friday 1st January, 1999 | First Prev Next Last |
|
|