Time Stamp

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.

 

/*

 * Copyright (C) 2006 Intel Corporation.  All rights reserved.

 *

 * The information and source code contained herein is the exclusive

 * property of Intel Corporation and may not be disclosed, examined,

 * or reproduced in whole or in part without explicit written

 * authorization from the Company.

 *

 * [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;

}