Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matlab tic toc equivalent in C++

Tags:

c++

time

timer

I have searched but I can't find an equivalent to the matlab tic/toc function to simply display on the console how long time took the program to do its processing. (ideally I would like to put the tic (start timer) and toc (end timer) anywhere in the program.

Any suggestions?

like image 692
George Avatar asked Jun 18 '12 14:06

George


1 Answers

I found what I was looking for. Include:

#include <ctime>

Then at the beginning:

 time_t tstart, tend; 
 tstart = time(0);

And finally before the end:

tend = time(0); 
cout << "It took "<< difftime(tend, tstart) <<" second(s)."<< endl;
like image 188
George Avatar answered Sep 22 '22 15:09

George