in Operating System edited by
196 views
0 votes
0 votes

Which of the following runs fastest (assume page size is 4096 bytes)?


a) int i, j, npages = 10000;
char *arr;
arr = (char*)malloc(4096*(npages+1));
for (i=0 ; i < npages ; i++) {
for (j=0 ; j < 4096 ; j++) {
arr[i+j] += 1;
}
}


b) int i, j, npages = 10000;
char *arr;
arr = (char*)malloc(4096*(npages+1));
for (i=0 ; i < npages*4096 ; i++) arr[i] += 1;


c) int i, j, npages = 10000;
char *arr;
arr = (char*)malloc(4096*(npages+1));
for (j=0 ; j < 4096 ; j++) {
for (i=0 ; i < npages ; i++) {
arr[i+j] += 1;
}
}

in Operating System edited by
196 views

1 comment

Please log in or register to answer this question.

Related questions