add parser and timings
This commit is contained in:
+2
-1
@@ -5,4 +5,5 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
console = "0.15.0"
|
console = "0.15.0"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
|
clap = { version = "3.1.15", features = ["derive"] }
|
||||||
|
|||||||
+16
-2
@@ -12,8 +12,19 @@ mod prelude {
|
|||||||
}
|
}
|
||||||
|
|
||||||
use 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() {
|
fn main() {
|
||||||
|
let args = Args::parse();
|
||||||
|
|
||||||
let term = Term::stdout();
|
let term = Term::stdout();
|
||||||
term.write_line("********** Rusty Propagation (Console) 2022 **********").expect("Oops Looks like we have a problem here...");
|
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...");
|
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];
|
let mut stats: [i32;4];
|
||||||
// = [0,0,0,0];
|
// = [0,0,0,0];
|
||||||
let mut counter:u32 = 0;
|
let mut counter:u32 = 0;
|
||||||
|
let now = Instant::now();
|
||||||
loop{
|
loop{
|
||||||
counter += 1;
|
counter += 1;
|
||||||
stats=population.propagate();
|
stats=population.propagate();
|
||||||
//population.display();
|
//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;}
|
if stats[1] == 0 {break;}
|
||||||
}
|
}
|
||||||
println!("Propagation finished in {} steps",counter);
|
println!("Propagation finished in {} steps, {:?}", counter, now.elapsed());
|
||||||
//population.display();
|
//population.display();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user