This code sample demonstrates how to use the _rdtsc()intrinsic to read the time stamp counter. The output is the current value of the 64-bit time stamp counter, and therefore varies each time you compile the code.
/*
* [Description]
* This code sample demonstrates how to use intrinsics to
* read the time stamp counter. The _rdtsc() function
* returns the current value of the processor's 64-bit time stamp counter.
*
* [Compile]
* icc time_stamp.c (linux) | icl time_stamp.c (windows)
*
* [Output]
* <varies>
*/
#include <stdio.h>
int main()
{
#if __INTEL_COMPILER
__int64 start, stop, elaspe;
int i;
int arr[10000];
start= _rdtsc();
for(i=0; i<10000; i++)
{
arr[i]=i;
}
stop= _rdtsc();
elaspe = stop -start;
printf("Processor cycles\n %I64u\n", elaspe);
#else
printf("Use INTEL Compiler in order to implement\n");
printf("_rdtsc intrinsic\n");
#endif
return 0;
}