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;
}
#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;
}
To copy to clipboard, switch view to plain text mode
edit: wysota beat me
Bookmarks