]> git.lizzy.rs Git - rust.git/commitdiff
Add performance notes to BufReader/BufWriter docs
authorMatt Brubeck <mbrubeck@limpet.net>
Mon, 2 Apr 2018 16:31:04 +0000 (09:31 -0700)
committerMatt Brubeck <mbrubeck@limpet.net>
Tue, 3 Apr 2018 22:25:55 +0000 (15:25 -0700)
src/libstd/io/buffered.rs

index cefff2f143ce70f52a398f381ba2ab1e1286d349..91f07ecc6639ef816d06f82b918cd10cda317b36 100644 (file)
 /// results in a system call. A `BufReader` performs large, infrequent reads on
 /// the underlying [`Read`] and maintains an in-memory buffer of the results.
 ///
+/// `BufReader` can improve the speed of programs that make *small* and
+/// *repeated* read calls to the same file or network socket.  It does not
+/// help when reading very large amounts at once, or reading just one or a few
+/// times.  It also provides no advantage when reading from a source that is
+/// already in memory, like a `Vec<u8>`.
+///
 /// [`Read`]: ../../std/io/trait.Read.html
 /// [`TcpStream::read`]: ../../std/net/struct.TcpStream.html#method.read
 /// [`TcpStream`]: ../../std/net/struct.TcpStream.html
@@ -359,6 +365,12 @@ fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
 /// `BufWriter` keeps an in-memory buffer of data and writes it to an underlying
 /// writer in large, infrequent batches.
 ///
+/// `BufWriter` can improve the speed of programs that make *small* and
+/// *repeated* write calls to the same file or network socket.  It does not
+/// help when writing very large amounts at once, or writing just one or a few
+/// times.  It also provides no advantage when writing to a destination that is
+/// in memory, like a `Vec<u8>`.
+///
 /// When the `BufWriter` is dropped, the contents of its buffer will be written
 /// out. However, any errors that happen in the process of flushing the buffer
 /// when the writer is dropped will be ignored. Code that wishes to handle such