All pastes #1433232 Raw Edit

Unnamed

public c v1 · immutable
#1433232 ·published 2009-05-24 19:06 UTC
rendered paste body
/* Code designed to test random reads and writes to a large array */#include <stdio.h>#include <stdlib.h>#include <math.h>#include <time.h>int main ( int argc, char *argv[] ){  int *p;  int i, val, temp, length;    if ( argc != 2 ) /* There should be one argument for correct execution */    {      /* We print argv[0] assuming it is the program name */      printf( "usage: %s length\n", argv[0] );      exit ( EXIT_FAILURE );    }  else    {      length = (int)strtol (argv[1], NULL, 10 );    }    // We use calloc now so we can read as well as write.  p = calloc(length, sizeof(int));      srand(time(NULL));    // We make a read and a write to each randomly chosen position in the array  for (i=0;i<length;i++) {       val = rand() % length;    temp +=  p[val];    p[val] = i; }    return temp;}