diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-11-13 07:20:33 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-11-13 07:20:33 -0500 |
commit | 6c439e27c47d0e2d4da9c2d253a57156bf32e5d8 (patch) | |
tree | 4c4f137ae707146fa8e4de93b8ca811162b4ba5d /examples/process_full.rs | |
parent | e85e57949df612e22463c06fc31fb0b7957ea3c7 (diff) | |
download | vt100-rust-direct-write.tar.gz vt100-rust-direct-write.zip |
attempt to avoid copies by writing directly to a std::io::Writedirect-write
this turns out to be slower, i think because it ends up doing a much
larger number of small writes, and the copying overhead isn't as high as
going through all of the machinery involved in stdout
locking/buffering/syscalls/etc.
Diffstat (limited to 'examples/process_full.rs')
-rw-r--r-- | examples/process_full.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/examples/process_full.rs b/examples/process_full.rs index 5aa5422..3be0ec0 100644 --- a/examples/process_full.rs +++ b/examples/process_full.rs @@ -1,4 +1,4 @@ -use std::io::{Read as _, Write as _}; +use std::io::Read as _; fn read_frames() -> impl Iterator<Item = Vec<u8>> { (1..=7625).map(|i| { @@ -12,12 +12,15 @@ fn read_frames() -> impl Iterator<Item = Vec<u8>> { } fn draw_frames(frames: &[Vec<u8>]) { - let mut stdout = std::io::stdout(); + let stdout = std::io::stdout(); + let mut stdout = stdout.lock(); let mut parser = vt100::Parser::default(); for frame in frames { parser.process(&frame); - let contents = parser.screen().contents_formatted(); - stdout.write_all(&contents).unwrap(); + parser + .screen() + .write_contents_formatted(&mut stdout) + .unwrap(); } } |