Buffered vs Unbuffered Reading
I have the following lines of code. The first chunk does a buffered reading using a 4Kb byte buffer. The other chunk does a sequential read.
When i measure the time taken by the two chunks of code i find out that unbuffered reading code takes less time then buffered reading code. While actually buffered should take less time.
Can any body tell me what i am doing wrong here.
//Buffered Read
string fileName="c:\\file";//open a 256 MB file
fileStream=new FileStream(fileName,FileMode.Open);
byte []readBuffer=new byte[4096];
while(fileStream.Read(readBuffer,0,readBuffer.Leng th)!=0)
{}
//Unbuffered Read
string fileName="c:\\file";//open a 256 MB file
fileStream=new FileStream(fileName,FileMode.Open);
int temp;
while((temp=fileStream.ReadByte())!=-1)
{}
|