Approved: Fortect
Last week, some of our readers ran into the Win32 high performance counter error. Several factors can cause this problem. We will talk about this below.
- 2 minutes to read.
Gets the current value of the performance counter, which represents the long response time (<1 μs) at which this buffer can be used for timing measurements.
Syntax
Approved: Fortect
Fortect is the world's most popular and effective PC repair tool. It is trusted by millions of people to keep their systems running fast, smooth, and error-free. With its simple user interface and powerful scanning engine, Fortect quickly finds and fixes a broad range of Windows problems - from system instability and security issues to memory management and performance bottlenecks.
BOOL QueryPerformanceCounter ( LARGE_INTEGER * lpPerformanceCount);
Parameters
A pointer to a variable gets this current value from a numeric performance counter.
Returned Value
If most of the functions don’t work, the return value is 0%. To get more information about raising an error, GetLastError . On systems running Windows XP or newer, the function will always succeed and therefore will probably never return zero.
For more information on this great feature and how to use it, see Recording high definition timestamps .
Examples
// Get the current number of ticks from QueryPerformanceCounter.Throws. away// Difference if the call to QueryPerformanceCounter fails.static th built-in int64_t GetTicks () LARGE_INTEGER works; if (! QueryPerformanceCounter (& Ticks)) winrt :: throw_last_error (); Ticks return.QuadPart;
Requirements
At least an enhanced professional client | Windows 2000 [desktop applications | UWP Apps] |
Minimum Supported Server | Windows 2000 Server [desktop applications | UWP Apps] |
Target Platform | Windows |
Title | profileapi.h (including Windows.h) |
Library | Kernel32.lib |
DLL | Kernel32.dll |
See Also
Not The Specific Answer You’re Looking For? Browse The Remaining Questions Flagged By Windows C ++ Timers And Ask Your Own Question.
#include double PCFreq = 0.0;__int64 CounterStart = 0;void StartCounter () LARGE_INTEGER li; if (! QueryPerformanceFrequency (& li)) cost << failed! notT "; "Query execution frequency PCFreq = double (li.QuadPart) / 1000.0; QueryPerformanceCounter (& li); CounterStart is equal to li.QuadPart;double GetCounter () Lee; large_integer QueryPerformanceCounter (& li); double return (li.QuadPart-CounterStart) / PCFreq;int main () StartCounter (); Sleep (1000); cost << << " n"; getcounter () returns 0;
This program should return a number close to 1000 (Windows hibernation has not finished yet, but should be 999).
The StartCounter ()
job registers the number of ticks this service has in the CounterStart
aspect. The GetCounter ()
function returns the associated number in milliseconds since the last call to startcounter ()
as a double, i.e. if GetCounter ()
takes precedence at 0.001, so the time for StartCounter ()
is approximately 1 microsecond.
was called
If you want the timer to use seconds, change it
PCFreq = double (left QuadPart) /1000.0;
PCFreq = double (left QuadPart);
PCFreq means double (li.QuadPart) /1000000.0;
587
answered on November 15 last year at 11:25 pm.
2.248
/ ** Use clock on initialization * /#define TIMER_INIT n LARGE_INTEGER frequency; n LARGE_INTEGER t1, t2; n passed twice; n QueryPerformanceFrequency (& frequency);/ ** Use to start a performance timer * /#define TIMER_START QueryPerformanceCounter (& t1);/ ** Use this parameter to stop a minute of performance and display the result on a given stream. Less verbose than c TIMER_STOP_VERBOSE * /#define TIMER_STOP n Query performance counter (& t2); n elapsedTime = (float) (t2.QuadPart-t1.QuadPart) /frequency.QuadPart; n std :: wcout << elapsedTime << L "sec" << endl;
TIMER_INIT TIMER_START Sleep (1000); TIMER_STOP TIMER_START Sleep (1234); TIMER_STOP
1 0.00003 sec.1.23407 s.
933
answered Apr 10, 2013 at 13:04
Assuming you are on Windows (so if you need to mark your question that way!), you can find a simple and handy C ++ HRTimer
class from the source code on this MSDN page. which supports the set calls needed to do something very close to your needs (it would be handy to add the GetTicks ()
method to the problem, especially to do exactly what you really need to do).
On non-Windows platforms, there is no QueryPerformanceCounter function, so the solution is not directly practical. However, if you re-encapsulate it in a class like It hrtimer
mentioned above, it will be easier to change the implementation of the class to take advantage of the current Platforms, no doubt, capable (maybe through a boost or something else!).
answered Nov 15 09 at 11:28 pm
775k
I would definitely add an example NDIS driver to save time on this question. As is particularly well known, KeQuerySystemTime (simulated in NdisGetCurrentSystemTime) has a resolution well below milliseconds, and eventually some technology networks, such as packets or future IRPs, may require a more satisfactory timestamp;
LONG_INTEGER data, frequency;LANGLON Diff;data = KeQueryPerformanceCounter ((LARGE_INTEGER *) & frequency)diff implies data.QuadPart / (Frequency.QuadPart / $ divisor)
answered Jan 21 12 at 14:12
2,686
Speed up your computer's performance now with this simple download.