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

26th Nov 2016, 6:27 AM
Antonio Andriollo
Antonio Andriollo - avatar
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; }
26th Nov 2016, 6:49 AM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 1
Just what I needed, thanks!
26th Nov 2016, 7:40 AM
Antonio Andriollo
Antonio Andriollo - avatar
+ 1
Hey, Antonio if you use laptop or computer for programing. Use codeblock it console tell you how much your program run.
26th Nov 2016, 9:35 AM
Aditya kumar pandey
Aditya kumar pandey - avatar
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.
26th Nov 2016, 9:38 AM
Antonio Andriollo
Antonio Andriollo - avatar