3 ms·
The C# version only makes a syscall if the buffer is empty: https://github.com/dotnet/runtime/blob/1ba0394d71a4ea6bee7f6b28a22d666b7b56f913/src/libraries/System
by withinboredom 5y ago
The C# version only makes a syscall if the buffer is empty: https://github.com/dotnet/runtime/blob/1ba0394d71a4ea6bee7f6b28a22d666b7b56f913/src/libraries/System.Private.CoreLib/src/System/IO/StreamReader.cs#L304 https://github.com/dotnet/runtime/blob/1ba0394d71a4ea6bee7f6...
To read in binary, you open with 'rb' and not just 'r'
- Mindless2112 5y agoSyscalls are not the only consumer of wall clock time, which is what was measured. > To read in binary, you open with 'rb' and not just 'r'. No. "The default translation mode is 'b'." [1] And even in 't' mode, it's still reading bytes in PHP vs UCS-2 characters in C#. [1] https://www.php.net/manual/en/function.fopen.php https://www.php.net/manual/en/function.fopen.php
- deltaci 5y agobut it makes function calls, it's not neglectable as it's called as many time as the bytes the file has
- withinboredom 5y agoThat’s the api provided, and part of the point. The other option is to read the buffer directly, but it isn’t exposed to the programmer.
- deltaci 5y agoYou just need to do File.OpenRead instead of OpenText to get a FileStream, then you can read the buffer
- h3h3 5y agothe overload is right below it int StreamReader.Read() int StreamReader.Read(char[] buffer, int index, int count) https://github.com/dotnet/runtime/blob/1ba0394d71a4ea6bee7f6b28a22d666b7b56f913/src/libraries/System.Private.CoreLib/src/System/IO/StreamReader.cs#L347 https://github.com/dotnet/runtime/blob/1ba0394d71a4ea6bee7f6...