I just decided to post the way i profile my programs. I'll attempt to use inline ASM so that it can be used in most of your C++ programs.
The instruction RDTSC is a highly accurate timer used by the x86 instruction set. it returns the current clock cycle in EDX:EAX this means it returns a 64 bit integer in two 32 bit registers. making it ideal for most timing applications.
Note the instruction does take time to call it's self and any other instructions used (ex: for saving the result) are not accounted for, so timeings will be a little longer than the actual time of your instructions.
Reasons for it's use: it can be used to get an idea of actual time a function or set of instructions really take. It can be used with optimized code (which a lot of profilers can't). and it's more accurate than the C and C++ timing functions. and it can be used to time multipul functions
Ok. enough background now for some functions.
inline void start_profile(void *ptr64bitint)
{
_ASM {
RDTSC
mov [ptr64bitint + 4], edx
mov [ptr64bitint], eax
}
return;
}
the above code should save the current clock to a pointer to a 64 bit int
now for some code that will use that will subtract the total time from that number
inline unsigned int end_profile(void *ptr64bitint)
{
_ASM {
RDTSC
sub [ptr64bitint + 4], edx
sbb [ptr64bitint], eax
}
return (unsigned int)(void)(*(ptr64bitint))
)
the return should be an unsigned 32 bit int containing the 32 least significant bits of the 64 bit pointer, which for most applications is enough. in some cases you may need to access the 64 bit number directly. either way the return should contain the amount of time between RDTSC calls in what ever unit system your processor uses. (AMD processors will use an actual clock count giving you a total amount instruction cycles taken.)
the code used here is untested and may contain bugs please feel free to post corrections and i will update the code accordingly.
// fixed code to properly save in little edian.