I wrote a program to read a 5MB file and perform some operation on it. I did it in two ways, first one is to read 1MB at a time, perform opeartion and read next 1MB
char line[1024*1024];
while(!feof(file1))
{
k = fread(line,1024*1024,1,file1);
for(i=0;i<strlen(line)-1;i++)
line[i] = line[i+1];
}
the next method is to read the 5MB at a time and perform operation.
char line[5*1024*1024];
while(!feof(file1))
{
k = fread(line,5*1024*1024,1,file1);
for(i=0;i<strlen(line)-1;i++)
line[i] = line[i+1];
}
the first one got completed in 3 minutes where as the second one took 26 minutes. My cache size is 3MB. Is there any significance of cache in making this difference? When I tried reading 3MB and doing operation and further reading remaining, it took 15 minutes. So I am totally clueless why this is happening. Plese tell how this is getting executed and why am I getting such a huge difference in execution time.