Skip to content

Commit 390f836

Browse files
committed
Add performance notes to BufReader/BufWriter docs
1 parent 1ce98f3 commit 390f836

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/libstd/io/buffered.rs

+12
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ use memchr;
2525
/// results in a system call. A `BufReader` performs large, infrequent reads on
2626
/// the underlying [`Read`] and maintains an in-memory buffer of the results.
2727
///
28+
/// `BufReader` can improve the speed of programs that make *small* and
29+
/// *repeated* read calls to the same file or network socket. It does not
30+
/// help when reading very large amounts at once, or reading just one or a few
31+
/// times. It also provides no advantage when reading from a source that is
32+
/// already in memory, like a `Vec<u8>`.
33+
///
2834
/// [`Read`]: ../../std/io/trait.Read.html
2935
/// [`TcpStream::read`]: ../../std/net/struct.TcpStream.html#method.read
3036
/// [`TcpStream`]: ../../std/net/struct.TcpStream.html
@@ -359,6 +365,12 @@ impl<R: Seek> Seek for BufReader<R> {
359365
/// `BufWriter` keeps an in-memory buffer of data and writes it to an underlying
360366
/// writer in large, infrequent batches.
361367
///
368+
/// `BufWriter` can improve the speed of programs that make *small* and
369+
/// *repeated* write calls to the same file or network socket. It does not
370+
/// help when writing very large amounts at once, or writing just one or a few
371+
/// times. It also provides no advantage when writing to a destination that is
372+
/// in memory, like a `Vec<u8>`.
373+
///
362374
/// When the `BufWriter` is dropped, the contents of its buffer will be written
363375
/// out. However, any errors that happen in the process of flushing the buffer
364376
/// when the writer is dropped will be ignored. Code that wishes to handle such

0 commit comments

Comments
 (0)