All pastes #954682 Raw Edit

Someone

public text v1 · immutable
#954682 ·published 2008-03-24 01:22 UTC
rendered paste body
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>



int main(int argc, char **argv) {

FILE* handle = fopen("A3.data", "r");

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++)
{
srand (time(0));

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++)
{
int i = 0;
int s = 0;
s = 1024*1024-1;
i = (rand() % s);

fseek(handle, i, SEEK_SET);

int j = 0;
j = i;
for(;j<block_size;j++)
  getc(handle); 
}

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;
}