rdtsc code that shows performance impacts from memory characterstics such
as TLB miss
I was trying to understand rdtsc() and I came across the following code
from http://www.mcs.anl.gov/~kazutomo/rdtsc.html.The text explaining the
code reads "The next short benchmark code may show you some performance
impacts from memory characteristic such as TLB miss, page fault or page
swap in/out.".The problem is that I don't really understand how this shows
performance from memory characterestics.Honestly I don't have a clue.It
would be great if someone could explain this a little bit.
#include <stdio.h>
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#include "rdtsc.h"
#define N (1024*1024*2)
int main(int argc, char* argv[])
{
unsigned long long a,b;
unsigned long long min,max;
char* p;
int i;
p = (char*)malloc(N);
assert( p!=(char*)0 );
max = 0;
min = UINT64_MAX;
for(i=0; i<N; i++ ) {
a = rdtsc();
p[i] = 0;
b = rdtsc() - a;
if( b > max ) max = b;
else if( b < min ) min = b;
}
printf("min=%llu\n", min);
printf("max=%llu\n", max);
return 0;
}
No comments:
Post a Comment