0
How to output run time in c++ program?
I would like a simple snipplet that shows how to output the running time of a c++ program to compare the performance of different versions
4 Answers
+ 7
You can use
#include <iostream>
#include <ctime>
using namespace std;
int main() {
clock_t begin = clock();
//Do your stuff here
clock_t end = clock();
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
cout << "Time taken: " << elapsed_secs << endl;
return 0;
}
+ 1
Just what I needed, thanks!
+ 1
Hey, Antonio if you use laptop or computer for programing. Use codeblock it console tell you how much your program run.
0
Thanks for the tip!
I'm only using the mobile app right now, when I will use a PC again I will give it a try.