High Resolution Timer Library in C ++ Windows?

Possible duplicate:
C ++ High Accuracy Measurement on Windows

I am developing a program that downloads files with ftp, and I am looking for a High-Res timer library to calculate the download speed, now I use C ++ time (NULL), but the results are not accurate.

Is there a simple / easy-to-use, plug-in N-shaped view of the C ++ library for the Windows platform? Something that gives time elapsed seconds after the last call or something like that.

EDIT:

So QueryPerformanceCounter () has been mentioned many times, but going through other threads is what I found out:

You should be warned that it is based on processor frequency. This frequency is unstable when, for example, the power saving mode is turned on. If you want to use this API, make sure that the CPU is at a constant frequency.

Keep in mind that Intel SpeedStep technology can change PerformanceFrequency without notifying your code.

* We also tried to fix the affinity of the thread for our threads to ensure that each thread always received a consistent value from the QueryPerformanceCounter, it worked, but it absolutely killed the performance in the application. *

So, given the situation, is it appropriate to use it? Program effectiveness and timer reliability are very important.

+4
source share
3 answers

You have a QueryPerformanceCounter, provided that you do not get into the buggy use case described in the notes in the MSDN docs

Example from: How to use QueryPerformanceCounter?

#include <windows.h> double PCFreq = 0.0; __int64 CounterStart = 0; void StartCounter() {   LARGE_INTEGER li;   if(!QueryPerformanceFrequency(&li)) cout << "QueryPerformanceFrequency failed!\n";   PCFreq = double(li.QuadPart)/1000.0;   QueryPerformanceCounter(&li);   CounterStart = li.QuadPart; } double GetCounter() {   LARGE_INTEGER li;   QueryPerformanceCounter(&li);   return double(li.QuadPart-CounterStart)/PCFreq; } int main() {   StartCounter();   Sleep(1000);   cout << GetCounter() <<"\n";   return 0; } 
+3
source

If you have a compiler that supports C ++ 11, then you can just use std::chrono , if not then boost::chrono at your service

+2
source

Use timeGetTime , the resolution should be sufficient for your needs.

+1
source

All Articles