aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-11-13 07:20:33 -0500
committerJesse Luehrs <doy@tozt.net>2019-11-13 07:20:33 -0500
commit6c439e27c47d0e2d4da9c2d253a57156bf32e5d8 (patch)
tree4c4f137ae707146fa8e4de93b8ca811162b4ba5d /examples
parente85e57949df612e22463c06fc31fb0b7957ea3c7 (diff)
downloadvt100-rust-6c439e27c47d0e2d4da9c2d253a57156bf32e5d8.tar.gz
vt100-rust-6c439e27c47d0e2d4da9c2d253a57156bf32e5d8.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')
-rw-r--r--examples/process_diff.rs12
-rw-r--r--examples/process_full.rs11
2 files changed, 13 insertions, 10 deletions
diff --git a/examples/process_diff.rs b/examples/process_diff.rs
index c141269..55ebbf2 100644
--- a/examples/process_diff.rs
+++ b/examples/process_diff.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| {
@@ -14,13 +14,13 @@ fn read_frames() -> impl Iterator<Item = Vec<u8>> {
fn draw_frames(frames: &[Vec<u8>]) {
let mut stdout = std::io::stdout();
let mut parser = vt100::Parser::default();
- let mut screen = parser.screen().clone();
for frame in frames {
+ let screen = parser.screen().clone();
parser.process(&frame);
- let new_screen = parser.screen().clone();
- let diff = new_screen.contents_diff(&screen);
- stdout.write_all(&diff).unwrap();
- screen = new_screen;
+ parser
+ .screen()
+ .write_contents_diff(&mut stdout, &screen)
+ .unwrap();
}
}
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();
}
}