
CCPUTicker v1.26 An ultra high precision MFC timing
class for Pentium or greater CPU's
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 2000 MHz. The value returned is
a 64 bit
integer so assuming your CPU runs at 2000 MHZ, the value will take roughly 300 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 itself was developed originally by J.M.McGuiness and continues to be co-developed by both authors.
The enclosed 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".
Copyright
- You are allowed to include the source code in
any product (commercial, shareware, freeware or otherwise) when your product
is released in binary form.
- You are allowed to modify the source code in
any way you want except you cannot modify the copyright details at the top
of each module.
- If you want to distribute source code with
your application, then you are only allowed to distribute versions released
by the author. This is to maintain a single distribution point for the
source code.
Updates
V1.0 (26 March 1996)
V1.1 (16 July 1997)
- Support for running on Windows NT
- now uses the build-in 64 bit data type "__int64"
- Improved diagnostic info thanks to the above
- Usage of static variables to improve efficiency
- Addition of a function which will convert from CPU ticks to seconds
- Improved adherence to the MFC coding style and standards
V1.2 (14 January 1999)
- Fixed a bug discovered by David
Green-Seed where he was experiencing access violations when the code was compiled with
optimizations turned on on a Pentium II. The problem was that (on a PII) the 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.
- Provision of HTML documentation (this file) for the class.
- A Visual C++ 5.0 workspace file is now provided as standard.
- Code now compiles cleanly at warning level 4.
- General code tidy up of const functions, parameters etc.
- Sample program now also reports the "Up" time of the
computer.
V1.21 (14 January 1999)
- No code changes included. Just updated the help file regarding some
development notes which may be of interest to the user of CCPUTicker.
21 January 1999
- No code changes included. Just updated this file regarding use on SMP
machines
27 January 1999
- No code changes included. Just updated this file regarding use on SMP
machines
v1.22 (3 December 1999)
- Fixed a problem in when compiling in VC 6 in release
mode.
v1.23 (17 May 2000)
- Measure method now returns the value measured.
- Code is now UNICODE enabled and build configurations
are provided.
30 July 2000
- The distributed zip file has now been updated to
include a sample app using CCPUTicker which was supplied by Michael Kennedy.
v1.24 (30 January 2001)
- Minor changes to the GetTickCountAsSeconds function.
- Updated the sample app to report the processor
frequency
- Added a GetCachedCPUFrequency function
v1.25 (23 February 2004)
- Now uses VC 6 SP5's and later support for built in
assembler support for cpuid and rdtsc. Thanks to Matthew Hurd for reporting
this. This does mean that the code will only compile on VC 6 SP5 or
later now.
v1.26 (24 December 2006)
- Updated copyright details
- Removed derivation from CObject as it was not really required
- Updated documentation to use the same style as my web site
- Addition of a CCMC_EXT_CLASS preprocessor macro to allow the classes to
be more easily added to an extension dll
- Reviewed all TRACE statements for correctness
- Code now uses newer C++ style casts instead of C style casts.
- Removed code which disables interrupts from CCPUTicker::Measure
- Code now uses "cmath" instead of math.h"
- Code now assumes that RDTSC is always available. This is no longer a big
issue since there are not that many 386/486 machines around!
- Updated the code to clean compile on VC 2005
- Updated the code to support x64 bit Windows
- Removed the member variable m_TickCount from the class
- Changed the default interval for GetCPUFrequency to 100 milliseconds
from 1000 milliseconds.
- Removed now unnecessary CCPUTicker constructor
4 September 2007
- Minor update to the documentation to refer to a download from AMD to
address synchronisation of the timestamp on SMP/Multi-core processors.
Thanks to Nicola Campanelli for reporting this issue.