|
Broken links? Email us! |
|
CCPUTicker
, An ultra high precision MFC timing class for
Pentium or greater CPU's resolution timing.
Features |
History |
API Reference |
Usage |
Contacting the Author |
Features
This class implements an MFC wrapper class for the Pentium-specific time stamp
counter which can be accessed using the RDTSC
assembly language instruction.
This counter has a resolution in terms of PCLKS (processor clocks) so if you have a 200
MHz CPU then this class will give a frequency of 200 MHz. The value returned is
a 64 bit integer so assuming your CPU runs at 200 MHZ, the value will take roughly
3000 years to roll over. As the value also starts counting from 0, the value returned
is the number of CPU ticks since the computer was turned on i.e. the "UP" time.
Because the timer is part of the CPU hardware, it is unaffected by processor activity and workload. The class has only been tested on Intel CPU's. Feedback about its behavior on other CPU types would be appreciated. The class can also be used on Windows NT without any problems.
The class itself was developed originally by J.M.McGuiness and continues to be co-developed by both authors.
The source zip file contains the CCPUTicker
source code and also includes a
simple MFC message box based demonstration application which will time the accuracy of a
call to the SDK call Sleep(1000)
and also report how long your machine has
been "Up".
History
V1.0 (26 March 1996)
V1.1 (16 July 1997)
__int64
.
V1.2 (14 January 1999)
RDTSC
instruction touches more registers than
expected. This has now been fixed by saving and restoring the EAX and EBX registers
around the call to RDTSC
.
V1.21 (14 January 1999)
CCPUTicker
.
21 January 1999
27 January 1999
v1.22 (3 December 1999)
API Reference
The API is made of the following public methods of the CCPUTicker
class:
CCPUTicker()
operator=()
Measure()
GetTickCountAsSeconds()
GetTickCount()
GetCPUFrequency()
IsAvailable()
AssertValid()
Dump()
Parameters:
Remarks:
Standard constructor and copy constructor for the class which just
initialize some internal variables.
Parameters:
Return Value:
Usual reference to this from a C++ operator= function.
Remarks:
Standard operator= for the class.
Remarks:
Calling this function retrieves the current value of the RDTSC
counter into this CCPUTicker instance.
Return Value:
The current RDTSC counter value in seconds.
Remarks:
Calling this function retrieves the stored value of the RDTSC
counter from this instance as seconds. The number of seconds is the "Up" time of
the computer. Because the counter is stored in clock ticks, the first time this function
is called by any of your code, the processor clock frequency will be estimated using an
internal timing routine. Please note that this can appear to hang the current process for
up to 20 seconds when this is being performed. Please see the Usage
section below for important development notes regarding this function.
Return Value:
The current RDTSC counter value in clock ticks.
Remarks:
Calling this function retrieves the stored value of the RDTSC
counter from this instance as clock ticks. This function is a simple accessor on the value
which the class will have obtained on the last call to its Measure method.
Parameters:
Return Value:
TRUE if the CPU frequency was returned successfully, otherwise FALSE. Use
GetLastError()
to determine the cause if this happens.
Remarks:
This function will work out the processor clock frequency to a
specified accuracy determined by the target average deviation required. Note that the
worst average deviation of the result is less than 5MHz for a mean frequency of 90MHz. So
basically the target average deviation is supplied only if you want a more accurate
result, it won't let you get a worse one. (Units are Hz.). The average deviation is a
better and more robust measure than it's cousin the standard deviation of a quantity. The
item determined by each is essentially similar. See "Numerical Recipies",
W.Press et al for more details. This function will run for a maximum of 20 seconds by
default before giving up on trying to improve the average deviation, with the average
deviation actually achieved replacing the supplied target value. Use "max_loops"
to change this. To improve the value the function converges to increase
"interval" (which is in units of ms, default value=1000ms). Please see the Usage section below for important development notes regarding this
function.
Return value:
TRUE if this machine has the "RDTSC" instruction available for timing
otherwise FALSE.
Remarks:
Standard MFC diagnostic function.
Remarks:
Standard MFC diagnostic function.
Usage
The sample app is a simple MFC message box based demonstration which will time the
accuracy of a call to the SDK call Sleep(1000)
and also report how long your
machine has been "Up".
To use CCPUTicker
in your project simply include cputicker.cpp from
the test application in your application and #include "cputicker.h"
in which ever
files you want to use the class.
The following points should be born in mind when developing code with CCPUTicker
:
Contacting the Author
PJ Naughter
Email: pjn@indigo..ie
Web:
|
|
|