View Full Version : How to check the rapidity of execution of a method during runtime ?
yellowmat
7th December 2006, 08:31
Hi everybody.
I have an application with some function, some of them are identical but coded differently. I want to test each of these identical functions in order to know which one is the fastest during runtime.
If I add some specific code in my applycation for the test, it will probably interfere with the results no ? Does someone know a way to process such tests, what should I take care during the developpment of the test architecture ?
Thanks in advance.
Methedrine
7th December 2006, 09:42
You are looking for a way to profile your code. Take a look at, for example gprof (which comes with gcc).
yellowmat
7th December 2006, 09:46
I am using VC++ 6.0 so it won't be possible to use gprof. Can you tell me more about code profiling ?
What I want to know is the time spended in some function in ordre to try, test and validate some kind of implementation for many similar functions.
wysota
7th December 2006, 09:53
Then use a profiler suited for MSVC :) There probably is one. You also probably have to pay for it, but I guess you're ready for that if you decided to use MSVC.
Of course you can make pseudo-tests using your code directly. Just use some way to measure time differences (for example using time() or clock()).
Methedrine
7th December 2006, 09:59
At work we used to use intel's v-tune for profiling purposes with visual c++ applications.
However, if you are only interested in how long a certain function runs you might as well just take the start and end time and substract start from end to get the runtime, for instance like this:
#include <iostream>
#include <ctime>
using namespace std;
void myFunction()
{
int j = 0;
for (int i = 0; i < 1000000; ++i)
{
++j;
}
}
void main(int argc, char** argv)
{
// start benchmarking
double truntime=0.0, tstart;
tstart = clock();
myFunction();
// end benchmarking
truntime += clock() - tstart;
// rescale to seconds
truntime /= CLOCKS_PER_SEC;
cout << "Runtime was: " << truntime << " seconds." << endl;
return 0;
}
edit: wysota beat me :p
yellowmat
7th December 2006, 11:47
Ok, I know now what profiling is and found were to enable this feature in MSVC. I think it will be enough for my need.
Thanks to all.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.