/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

const int REP = 20;
const int N = 10000000;

void test(int offset)
{
   int i,j;
   time_t t1,t2;
   int *a;
   a=(int*)(((char*)malloc(N*sizeof(int)+offset))+offset);
   t1 = time(NULL);
   for(i=0;i<REP;i++)
   {
      for(j=0;j<N;j++)
      {
         a[j] = j;
      }
   }
   t2 = time(NULL);
   free(a);
   printf("%d array accesses in %d seconds with offset %d\n",REP*N,t2-t1,offset);
}

int main()
{
   test(0);
   test(1);
   return EXIT_SUCCESS;
}
