Write using a BufWriter for +10% speed

This commit is contained in:
Keenan Tims 2023-03-23 11:17:58 -07:00
parent 675cda945f
commit 7c74cd6f7a
Signed by: ktims
GPG Key ID: 11230674D69038D4

View File

@ -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();
}
}