News for hackers. Stuff that matters.
Re:Yes, PHP is faster than C# by alkonaut on Wednesday March 16, 2022 @07:46PM (#30705638)
Isn’t this reading the file in 4K chunks in the php version and byte by byte in the C# version? If so they are completely different programs. The C# program would have 4096 times the number of method calls to Read()?

Edit: To clarify it’s buffered in C# too but the difference is that it’s fetched one byte at a time via a method call per byte. Not an I/O call per byte (then the difference would have been much larger of course).

Re:Yes, PHP is faster than C# by notRobot on Wednesday March 16, 2022 @07:51PM (#30705696)
This is addressed in the article:

> “But Rob,” I hear you say, “they’re not reading it byte-by-byte in the PHP version!” and I’d reply with, “but we’re not reading it byte-by-byte in the C# version either!”

C# also reads in 4K chunks: https://github.com/dotnet/runtime/blob/1ba0394d71a4ea6bee7f6...

Re:Yes, PHP is faster than C# by alkonaut on Wednesday March 16, 2022 @07:55PM (#30705736)
That just means there aren’t 4K times as many file read ops.

The read() calls (which most of the time just increment the index into the buffer and returns what’s there) are still made.

The usual way of doing what he’s trying to do will look exactly the same in C# as in his php version, with explicit buffering.

Re:Yes, PHP is faster than C# by withinboredom on Wednesday March 16, 2022 @07:50PM (#30705678)
You can follow the link to the underlying C# library where it is reading it in 4kb chunks as well. PHP doesn’t buffer for you, so if you want to read a file one byte (to your peril) at a time, you can. It’ll be as fast as the async version of the C# implementation, but still slower than reading buffered.
Re:Yes, PHP is faster than C# by alkonaut on Wednesday March 16, 2022 @08:05PM (#30705830)
Both of these programs will make the same I/O calls but the total number of method invocations will differ by a factor 4096 unless I’m mistaken (it’s late). Those are cheap, but not free.