PC Review


Reply
Thread Tools Rate Thread

C# strange cache behaviour

 
 
Gwl
Guest
Posts: n/a
 
      1st May 2007
I made some test to mesure the c# read perfomance on binary file and I
made some curious discovery. Except for some minor details, the
following is the code I used to read the file:

byte[] buffer = new byte[bufferSize];
FileStream fileStream = new FileStream(fileName,
FileMode.Open,
FileAccess.Read, FileShare.None, fileStreamBufferSize,
fileOptions);
BinaryReader stream = new BinaryReader(fileStream);
int itemRead;
while (true)
{
itemRead = stream.Read(buffer, 0, bufferSize);
if (itemRead == 0) //end of file
break;
}

The interesting things happen playing with the fileOptions parameter.
Its type is an enumeration and twos of the admitted value are:

* FileOptions.SequentialScan
* FileOptions.None

I ran the above code consecutively 8 times on a 100MB files varying
fileOptions value. Here it is the results according the FileOptions
value:

1 FileOptions.SequentialScan: 20.05 MB/Sec
2 FileOptions.SequentialScan: 20.25 MB/Sec
3 FileOptions.SequentialScan: 20.40 MB/Sec
4 FileOptions.SequentialScan: 20.39 MB/Sec
5 FileOptions.None: 16.55 MB/Sec
6 FileOptions.None: 704.23 MB/Sec
7 FileOptions.SequentialScan: 680.27 MB/Sec
8 FileOptions.SequentialScan: 694.44 MB/Sec

I expected to see the cache effect show up starting from the second
read but this does not happen until sixth read. I repeated the test
many times and the system cache never (with the exception I will
discuss further) start to cache at first read. In my tests caching
starts only when I open the file using FileOptions.None. After that
moment all further read take advantage of the cache system. Any idea
what's happening? I made some more test and collect them here:
http://www.dragoncello.com/blog/

g.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Internet Explorer Browser Cache Behaviour =?Utf-8?B?Q2hhcmxpZSBCYXJrZXI=?= Windows XP Internet Explorer 0 27th Oct 2005 04:10 PM
Strange behaviour Aunim Pierre Windows XP Internet Explorer 0 16th Oct 2004 10:41 AM
Strange cache behaviour snowball Windows XP Internet Explorer 0 5th Oct 2004 01:25 AM
strange behaviour. Steve.UK Windows XP Performance 1 14th Feb 2004 03:11 AM
strange behaviour david turnbull Microsoft Windows 2000 Active Directory 0 21st Aug 2003 12:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:31 PM.