Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

Performance of FileStream.ReadByte() versus FileStream.Read

$
0
0

Hi,

I'm going to be processing files 1 byte at a time.  I used Reflector to look at implementation of FileStream.ReadByte and FileStream.Read. 

Both "ReadByte" and "Read" use an internal byte array called ".buffer" and read "BufferSize" (default 4096) bytes at a time into the byte array.  ReadByte returns 1 byte at a time from this array; and "Read" copies 1 or more times from the internal array to the array you pass it.

It seems like each has a weakness; ReadByte() would involve orders-of-magnitude more calls to the function, but Read copies the data an extra time.  I can't predict would be worse but my intitution would be that ReadByte() would be worse, although it would be simpler for me to code.

Before I write some tests myself is there a general recommendation?


Viewing all articles
Browse latest Browse all 8156


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>