mirror of
				https://github.com/ktims/rs-aggregate.git
				synced 2025-10-30 10:12:29 -07:00 
			
		
		
		
	Write using a BufWriter for +10% speed
This commit is contained in:
		
							
								
								
									
										12
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/main.rs
									
									
									
									
									
								
							| @@ -1,16 +1,18 @@ | |||||||
| extern crate ipnet; | extern crate ipnet; | ||||||
| extern crate iprange; | extern crate iprange; | ||||||
|  |  | ||||||
| use std::process::exit; | use std::{process::exit, io}; | ||||||
|  |  | ||||||
| mod iputils; | mod iputils; | ||||||
| use iputils::{IpBothRange, IpOrNet, PrefixlenPair}; | use iputils::{IpBothRange, IpOrNet, PrefixlenPair}; | ||||||
|  |  | ||||||
| use clio::*; | use clio::*; | ||||||
| use std::io::BufRead; | use std::io::{Write, BufRead}; | ||||||
|  |  | ||||||
| use clap::Parser; | use clap::Parser; | ||||||
|  |  | ||||||
|  | const WRITER_BUFSIZE: usize = 32 * 1024; | ||||||
|  |  | ||||||
| #[derive(Parser)] | #[derive(Parser)] | ||||||
| #[command(author, version, about, long_about=None)] | #[command(author, version, about, long_about=None)] | ||||||
| struct Args { | struct Args { | ||||||
| @@ -123,7 +125,11 @@ impl App { | |||||||
|  |  | ||||||
|         self.simplify_inputs(); |         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(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user