Buffered IO accumulates bytes from multiple writes to be written all at once. Unbuffered immediately writes the bytes to the disk. Since writing to the disk is slow, buffers significantly improve performance when multiple small write calls are issued, but should I use unbuffered if only a single write call is issued?
should I use unbuffered if only a single write call is issued?
You should write clear code, as simple as is feasible, using efficient algorithms appropriate to your purpose. You should not expend effort or extra lines of code to exert control over details such as I/O buffering unless there is a clear and significant win to be had, whether from reasoning about your code or from actual measurements of its behavior. As long as it is fast enough for the purpose, having code that is easy to understand and maintain is much more important than having the absolute speediest code possible.
With that said, buffering does not provide a performance advantage for a single write. In fact, buffering is probably more costly in that case.
HOWEVER, the extra cost will be very small on a per-write basis, compared to the cost of the actual I/O. You are unlikely to see a measurable performance difference between buffering and not in the one-write-ever case, so even if you were actually troubleshooting a performance problem, this would be an unlikely place to look.