Unbuffered reading and writing may be significantly slower; if you're writing a text file one line at a time, your code may make hundreds more system calls to ask the OS to write the file. Depending upon the speed in which you're writing to disk, this may even mean that the last block of the file needs to be re-read from disk in order to re-save the file with a new last line. (This might be rare; but more system calls are almost always a recipe for going slower.)
Here's a simple demonstration of the number of system calls having a large influence on write speed:
$ cat initrd.img-2.6.38-8-generic > /dev/null
The first line makes sure the file is in cache, so only output speed is being measured.
$ dd if=initrd.img-2.6.38-8-generic of=/tmp/out bs=16 oflag=dsync
^C262766+0 records in
262766+0 records out
4204256 bytes (4.2 MB) copied, 50.7754 s, 82.8 kB/s
I gave up waiting for this -- it's going way too slow. This is "unbuffered" writing 16 bytes at a time to disk, and making sure each write succeeded before moving on to the next. (That's the dsync
-- more on that later.)
$ dd if=initrd.img-2.6.38-8-generic of=/tmp/out bs=$((4096)) oflag=dsync
3218+1 records in
3218+1 records out
13181130 bytes (13 MB) copied, 3.69961 s, 3.6 MB/s
$ dd if=initrd.img-2.6.38-8-generic of=/tmp/out bs=$((4096 * 10)) oflag=dsync
321+1 records in
321+1 records out
13181130 bytes (13 MB) copied, 0.471143 s, 28.0 MB/s
These two commands show the effect of some buffering -- the first one writes data in 4096-byte chunks, which might be what the default buffering gives you. This is roughly fifty times faster than 16 bytes at a time. The second command is writing data in 40960 byte chunks, and it went roughly nine times faster still. (All told, it's roughly 345 times faster to write 40960 bytes at a time than 16 bytes at a time.)
If your data is small, this won't really matter. After all, it won't take much time either way. If your data is large, it might matter more, depending upon how much data you're writing at once and how often it lines up on happy "byte boundaries" for the underlying devices.