|
-
September 26th, 2009, 03:55 PM
#1
How to do profiling in c++
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
-
September 26th, 2009, 09:20 PM
#2
Re: How to do profiling in c++
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;
}
-
September 26th, 2009, 09:50 PM
#3
Re: How to do profiling in c++
If you're on Linux, you can compile using the -pg option to generate a gprof file.
-
September 27th, 2009, 06:17 AM
#4
Re: How to do profiling in c++
 Originally Posted by binaryHex
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;
}
To get the ticks taken to execute you must use (clk_end - clk_strt) and not the opposite.
-
September 27th, 2009, 07:57 AM
#5
Re: How to do profiling in c++
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....
-
September 27th, 2009, 09:09 AM
#6
Re: How to do profiling in c++
It compiles well on code::blocks.
-
September 27th, 2009, 01:31 PM
#7
Re: How to do profiling in c++
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.........
-
September 28th, 2009, 09:35 AM
#8
Re: How to do profiling in c++
hey salehhamadeh pls reply dude
-
September 28th, 2009, 09:48 AM
#9
Re: How to do profiling in c++
In old compilers (like Turbo C++), you probably have to use time.h instead of ctime
-
September 28th, 2009, 11:54 AM
#10
Re: How to do profiling in c++
thanks a lot philip..... It did work!!!!!![ ]
-
September 28th, 2009, 12:02 PM
#11
Re: How to do profiling in c++
Any compiler which doesn't support the C++ standard libraries is too old to be using. Ditch it.
-
September 28th, 2009, 02:37 PM
#12
Re: How to do profiling in c++
yeah u r right.... Mah college forces me 2 use it
-
September 29th, 2009, 03:42 AM
#13
Re: How to do profiling in c++
If you're forced to use it, then learning c would be better.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|