-
April 5th, 2010, 04:47 PM
#1
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.
-
April 5th, 2010, 05:12 PM
#2
Re: Timer in C++
maybe this link may help.
-
April 5th, 2010, 05:49 PM
#3
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.
-
April 6th, 2010, 06:17 AM
#4
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.
-
April 6th, 2010, 07:43 AM
#5
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|