This may be a problem with the implementation of a particular OS. I also believe that the stream buffer (buflen) is less than 10000, the typical value of which is 4095. So try to run with i <4096, and the response time should be the same!
The reason this happens faster in the second case:
In the first case, when the buffer is full (buflen = 4095bytes), it is written to disk. Thus, for i <10000 this should have been reset 3 times.
While in the second case, all data is first created in RAM, and in one case, it is flushed to the hard drive. Thus, two flushes were saved!
user5858
source share