I've to measure the time taken by a c++ program to execute and also the number of clock cycles that were required to do so. Please help fast I've a deadline to meet.
Thanks in advance
Printable View
I've to measure the time taken by a c++ program to execute and also the number of clock cycles that were required to do so. Please help fast I've a deadline to meet.
Thanks in advance
Use the ctime library for clocks. The code below has not been compiled.
Code:#include<iostream>
#include<ctime>
using namespace std;
int main()
{
const float clk_strt = float( clock() );
for(int i = 0; i < 100; i++ )
cout<<i<<" ";
const float clk_end = float ( clock() );
cout<<"\n\nThe number of ticks is taken to execute is: " << (clk_strt - clk_end) << endl;
return 0;
}
If you're on Linux, you can compile using the -pg option to generate a gprof file.
thanks guys for replying..... Am working on winxp operating system and I use turbo C++. This clock() function will give me the number of cpu clock cycles or the actual time taken to execute?..... And further when I tried compiling this program the compiler was unable to include the ctime library, I got the same error in Visual C++ as well....
It compiles well on code::blocks.
k.... I've also downloaded code::blocks......Can u tell me how to proceed further to run the program like which compiler to select etc etc..... Also if u kno a way to do all this in turbo c++ only then please tell.........
hey salehhamadeh pls reply dude
In old compilers (like Turbo C++), you probably have to use time.h instead of ctime
Code:#include <time.h>
thanks a lot philip..... It did work!!!!!![:D]
Any compiler which doesn't support the C++ standard libraries is too old to be using. Ditch it.
yeah u r right.... Mah college forces me 2 use it
If you're forced to use it, then learning c would be better.