I tried to print Hello World 200,000 times and it took me forever, so I have to stop. But right after I add a char array to act as a buffer, it took le
For the stand of file operations, writing to memory (RAM) is always faster than writing to the file on the disk directly.
For illustration, let's define:
Let's say we have to write some data to a file 100 times.
100 times x 1 ms = 100 ms
100 times x 5 ms = 500 ms
(100 times x 0.5 ms) + 1 ms = 51 ms
(100 times x 0.5 ms) + 5 ms = 55 ms
Buffering in memory is always faster than direct operation. However if your system is low on memory and has to swap with page file, it'll be slow again. Thus you have to balance your IO operations between memory and disk/network.