-
Timer in C++
Code:
#include<iostream>
#include<time.h>
using namespace std;
int main(void){
clock_t start, finish;
start=clock();
cout<<start<<endl;
cin.get();
finish=clock();
cout<<finish<<endl;
cin.get();
}
The above code displays outputs similar to:
It depends on how fast I hit the return key, of course. My question is: what is the unit of time displayed? I am guessing it to be milliseconds.
-
Re: Timer in C++
maybe this link may help.
-
Re: Timer in C++
Clock is more portable, but my experience is that it's not very accurate.
I usually use GetTickCount instead, which is usually 10-20ms accuracy on most modern systems. If you need greater accuracy, you can use timeGetTime as well.
-
Re: Timer in C++
Assuming you are interested in getting the time with high resolution the functions QueryPerformanceCounter and QueryPerformanceFrequency may be worth to be considered.
-
Re: Timer in C++
not that as you're doing it now. part of your timing includes the time needed to output the start time to the console.