I've never found a profiler I like that doesn't cost too much. A good recommendation would be appreciated.
In the mean time; If you look in the file textS.cpp you will see the following code:
Code:
// timer stuff for profiling
const int MAX_PROFILES = 10;
LARGE_INTEGER timeStart[MAX_PROFILES];
LARGE_INTEGER timeEnd;
LARGE_INTEGER timerFreq;
LARGE_INTEGER scoreTime;
float profileTimes[MAX_PROFILES];
//---------------------------------------------------------------------------
__fastcall TTextStuff::TTextStuff(TComponent* Owner)
: TForm(Owner)
{
InsertMode = true;
SourceText->DefAttributes->Protected = true;
QueryPerformanceFrequency(&timerFreq); // set up high resolution timer
}
//---------------------------------------------------------------------------
void __fastcall TTextStuff::ProfileStart(unsigned int n)
{
if (n >= MAX_PROFILES)
return;
QueryPerformanceCounter(&timeStart[n]); // get starting time
}
//---------------------------------------------------------------------------
void __fastcall TTextStuff::ProfileEnd(unsigned int n)
{
if (n >= MAX_PROFILES)
return;
QueryPerformanceCounter(&timeEnd);
profileTimes[n] += ( (float)timeEnd.QuadPart - (float)timeStart[n].QuadPart ) / timerFreq.QuadPart;
}
//---------------------------------------------------------------------------
void __fastcall TTextStuff::ProfileClear()
{
for (int i=0; i<MAX_PROFILES; i++)
profileTimes[i] = 0.0f;
}
This is what I created to profile the color syntax highlighter. You use it like this:
Code:
ProfileClear(); // do this to clear all times
..
// start of code to be timed
ProfileStart(n); // start a timer, where n is 0 to MAX_PROFILES-1
..
.. // code to be timed
ProfileEnd(n); // stop timing
The array profileTimes will contain the times. Yes it is crude. Feel free to add bells and whistles if you wish. I just looked at the contents of profileTimes using my C++ debugger. You need to include <time.h>