If you are unable to use the IDE to obtain a measurement of the amount of time a set of instructions are taking you can use the kernel call ClockCycles() and grab the number of CPU clock cycles and compare it to an earlier value to obtain the total elapsed cycles. Once you have this though you will likely want to know how long a clock cycle actually takes on your system as they vary between systems. This can be done via a syspage entry. Here is a simple example showing the ClockCycles as a measurement tool.
int main( void )
{
uint64_t cps, cycle1, cycle2, ncycles;
float sec;
cycle1=ClockCycles( ); /* snap the time */
printf("foo\n"); /* do something */
cycle2=ClockCycles( ); /* snap the time again */
ncycles=cycle2-cycle1;
printf("%lld cycles elapsed \n", ncycles);
/* find out how many cycles per second */
cps = SYSPAGE_ENTRY(qtime)->cycles_per_sec;
printf( "This system has %lld cycles/sec.\n",cps );
sec=(float)ncycles/cps;
printf("The printf function took %lld cycles which was %f seconds\n",ncycles, sec);
return EXIT_SUCCESS;
}
Note that the code above may not be accurate when running on modern x86 machines due to out-of-order execution. Intel suggests two different methods of improving measurement accuracy [download.intel.com/embedded/software/IA/324264.pdf]. The attached C file contains sample code implementing Intel's recommendation to use the "RDTSCP" instruction.
Please contact us with your questions or concerns.
BlackBerry uses cookies to help make our website better. Some of the cookies are necessary for the proper functioning of the website while others, non-essential cookies, are used to better understand how you interact with our website and to make it better.