#include <sys/time.h>
int main()
{
struct timeval start_time;
struct timeval end_time;
gettimeofday(&start_time, NULL);
stuff();
gettimeofday(&end_time, NULL);
// How do I see the runtime at the end?
cout << end_time.tv_sec - start_time.tv_sec << endl;
return 0;
}
That's the general idea, but unless your program runs for more than a second, seconds won't be meaningful. So you probably want to display the difference in microseconds also.