CPerfCounter v1.07
Welcome to CPerformanceCounter, A freeware C++ class which encapsulates the
performance counters API of Windows. The performance counter API on Windows is
composed of the SDK calls "QueryPerformanceFrequency" and "QueryPerformanceCounter".
These two methods provide a high frequency counter value (normally with a single
digit Megahertz frequency), which is synchronized across CPU cores. This is the
official way to implement high performance timers on Windows. Other approaches
such as the Pentium assembly language instruction of "RDTSC" are available
(wrapped by the CCPUTicker
class of the author) but the frequency of this counter can change as the
frequency of a CPU is changed based on technologies such as Intel SpeedStep.
Also on modern CPUs different cores can be slowed down individually meaning that
the value you get back can become inconsistent if your code is migrated from
core to core as it runs. This simple class avoids these issues while still
providing a simple and high speed API.
Usage
- To use CPerformanceCounter in your project simply #include "PerfCounter.h"
in whichever files you want to use the class in. Then create an instance of
CPerformanceCounter and call its methods as required.
- The class is only supported on VC 2017 or later.
- Included in the download is a VC 2017 console application which
demonstrates all of the class methods around a call to "Sleep(1000)".
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.
History
v1.07 (10 April 2022)
- Updated copyright details.
- Updated the code to use C++ uniform initialization for all variable
declarations.
v1.06 (16 December 2021)
- Made CPerformanceCounter class moveable and copyable. Thanks to J. Brian
Schaer for reporting this issue.
v1.05 (6 December 2021)
- Updated copyright details.
- Fixed more Clang-Tidy static code analysis warnings in the code.
v1.04 (2 June 2019)
- Updated copyright details
- Updated the code to clean compile on VC 2019
v1.03 (19 August 2018)
- Updated copyright details.
- Fixed a number of C++ core guidelines compiler warnings. These changes
mean that the code will now only compile on VC 2017 or later.
v1.02 (2 January 2016)
- Updated copyright details.
- Verified the code compiles cleanly on VC 2015.
v1.01 (5 April 2015)
- Updated copyright details.
v1.0 (30 March 2010)
Contacting the Author
PJ Naughter
Email: pjna@naughter.com
Web: http://www.naughter.com
10 April 2022