[ create a new paste ] login | about

Link: http://codepad.org/ENIvUr2H    [ raw code | output | fork ]

C++, pasted on Aug 16:
#include <stdio.h>

#ifdef __GNUC__
 #define ALIGN(n) __attribute__((aligned(n)))
#else
 #define ALIGN(n) __declspec(align(n))
#endif

typedef int (*rd)(void);

enum{ bufsize=1<<24 };
ALIGN(4096)
volatile char buf[bufsize];

int main( void ) {

  union {
    const char* rdtsc_s;
    rd rdtsc;
  };

  rdtsc_s = "\x0F\x31\xC3";

  printf( "buf=%08X bufsize=%i\n", (char*)buf-(char*)0, bufsize );

  int i,th,t1=0,t2=0,n=0;

  do {

    for( i=0; i<bufsize; i++ ) buf[i]=0;

    th = t1*t2; n++;

    t1 = rdtsc();
    buf[bufsize-4096];
    t1 = rdtsc() - t1;

    t2 = rdtsc();
    buf[0x123450];
    t2 = rdtsc() - t2;

  } while( th!=t1*t2 );

  printf( "n=%i\n", n );

  printf( "   t1=%08X %i\n", t1, t1 );

  printf( "   t2=%08X %i\n", t2, t2 );

  printf( "t2-t1=%08X %i\n", t2-t1, t2-t1 );

}


Output:
1
2
3
4
5
buf=08051000 bufsize=16777216
n=11
   t1=00000028 40
   t2=00000230 560
t2-t1=00000208 520


Create a new paste based on this one


Comments: