rendered paste body#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
int main(int argc, char **argv) {
int total_bytes_accessed;
int block_size;
int num_trials;
total_bytes_accessed = atoi(argv[1]);
block_size = atoi(argv[2]);
num_trials = atoi(argv[3]);
char *array = (char *) malloc( sizeof(char) * 1024 * 1024 );
int z = 0;
for(;z<num_trials;z++)
{
struct timeval start;
struct timeval end;
long elapsed;
gettimeofday( &start, NULL );
int repeat = 0;
repeat = total_bytes_accessed / block_size;
int q = 0;
for(;q<repeat;q++)
{
srand (time(0));
int i = 0;
int s = 0;
s = 1024*1024-block_size;
i = (rand() % s);
int j = 0;
j = i;
int sum = 0;
for(;j<i+block_size;j++)
sum = sum + array[j];
}
gettimeofday( &end, NULL);
elapsed = (end.tv_sec - start.tv_sec) * 1e6 + (end.tv_usec - start.tv_usec);
printf("Trial time: %ld microseconds\n",elapsed);
}
return 0;
}