add parser and timings

This commit is contained in:
2022-05-05 20:53:56 +02:00
parent bc13c48302
commit b8ea034a84
2 changed files with 18 additions and 3 deletions
+2 -1
View File
@@ -5,4 +5,5 @@ edition = "2021"
[dependencies]
console = "0.15.0"
rand = "0.8.5"
rand = "0.8.5"
clap = { version = "3.1.15", features = ["derive"] }
+16 -2
View File
@@ -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();
}