I did a c# only test (running in VS 2017 in a Win7 VM). Omitting file reading time, and conversion to text (for the string counters, and conversion to a byte array for the stream counting), I only timed the actual time required to count the occurrences of '1'. I averaged three runs for each situation. 0) The chosen file was a paintshop pro image file that was 4,046,848 bytes large. 1) I wrote a string (and MemorySream) extension method for each of the three counting styles. 2) Each count run was executed three times per counting style, and the result was averaged. 3) The duration calculation only included the actual time it took to count the number of '1' characters in the string/stream. Any conversion code that was performed was not included i the duration calculation. I found that the reported durations were *all over the map*. For instance, counting as a string with a .Where call took from 44ms to 147ms. All counting styles exhibited this behavior. However, some general observations could be made: 0) Using some variation of linq collection.Where(x=>x == '1') was always the slowest code. 1) Counting with a foreach loop was almost twice as fast for strings as using .Where, but streams were only about 1/3 faster than their string counterparts. 2) Counting with a normal for took about the same amount of time as the foreach code (the difference was +/- 2 ms. Again, the actual reported durations were all over the map, so mentioning them specifically would be kinda pointless. My considered opinion is that this article is just more bullshit from someone that tried to be a programmer and couldn't pull it off, so now he writes articles about programming, telling us (actual programmers) how we should do it.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013