[c++] get system time

I need to benchmark some of my function to see how long it takes for them to run.


is it possible to do this?

time = gettime()


cou << gettime() - time ;
TroudeloupAsked:
Who is Participating?
 
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
if you want only the difference in seconds, you can use time() function:

time_t t1 = time(NULL);
//do some tasks here
time_t t2 = time(NULL);

cout << "Lapse:" << (t2-t1) << "seconds" << endl;
0
 
Jaime OlivaresSoftware ArchitectCommented:
for milliseconds use GetTickCount();

DWORD t1 = GetTickCount();
//do some tasks here
DWORD t2 = GetTickCount();

cout << "Lapse:" << (t2-t1) << "miliseconds" << endl;
0
All Courses

From novice to tech pro — start learning today.