add parser and timings
This commit is contained in:
@@ -6,3 +6,4 @@ edition = "2021"
|
||||
[dependencies]
|
||||
console = "0.15.0"
|
||||
rand = "0.8.5"
|
||||
clap = { version = "3.1.15", features = ["derive"] }
|
||||
|
||||
+15
-1
@@ -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();
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user