From 7c74cd6f7af0a5b4ea25c7a480db0d1a564771ea Mon Sep 17 00:00:00 2001 From: Keenan Tims Date: Thu, 23 Mar 2023 11:17:58 -0700 Subject: [PATCH] Write using a BufWriter for +10% speed --- src/main.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index fde5459..cc1afa4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,18 @@ extern crate ipnet; extern crate iprange; -use std::process::exit; +use std::{process::exit, io}; mod iputils; use iputils::{IpBothRange, IpOrNet, PrefixlenPair}; use clio::*; -use std::io::BufRead; +use std::io::{Write, BufRead}; use clap::Parser; +const WRITER_BUFSIZE: usize = 32 * 1024; + #[derive(Parser)] #[command(author, version, about, long_about=None)] struct Args { @@ -123,7 +125,11 @@ impl App { self.simplify_inputs(); - print!("{}", self.prefixes); + let stdout = io::stdout().lock(); + let mut w = io::BufWriter::with_capacity(WRITER_BUFSIZE, stdout); + + write!(&mut w, "{}", self.prefixes).unwrap(); + w.flush().unwrap(); } }