From b8ea034a84cb12d96fc077024cbcb400e4a022aa Mon Sep 17 00:00:00 2001 From: Rene Luria Date: Thu, 5 May 2022 20:53:56 +0200 Subject: [PATCH] add parser and timings --- Cargo.toml | 3 ++- src/main.rs | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fb5c1e6..bef4adf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,4 +5,5 @@ edition = "2021" [dependencies] console = "0.15.0" -rand = "0.8.5" \ No newline at end of file +rand = "0.8.5" +clap = { version = "3.1.15", features = ["derive"] } diff --git a/src/main.rs b/src/main.rs index b428920..415a382 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,8 +12,19 @@ mod prelude { } use prelude::*; +use clap::Parser; +use std::time::Instant; + +#[derive(Parser, Debug)] +struct Args { + /// Display stats after each propagation + #[clap(short, long)] + display: bool, +} fn main() { + let args = Args::parse(); + let term = Term::stdout(); term.write_line("********** Rusty Propagation (Console) 2022 **********").expect("Oops Looks like we have a problem here..."); term.write_line("Press any key to start the propagation").expect("Oops Looks like we have a problem here..."); @@ -31,14 +42,17 @@ fn main() { let mut stats: [i32;4]; // = [0,0,0,0]; let mut counter:u32 = 0; + let now = Instant::now(); loop{ counter += 1; stats=population.propagate(); //population.display(); - println!("Infecteds: {} Immunes: {} Deads: {}",stats[1],stats[2],stats[3]); + if args.display { + println!("Infecteds: {} Immunes: {} Deads: {}",stats[1],stats[2],stats[3]); + } if stats[1] == 0 {break;} } - println!("Propagation finished in {} steps",counter); + println!("Propagation finished in {} steps, {:?}", counter, now.elapsed()); //population.display(); }