display time take

This commit is contained in:
2022-05-05 20:40:56 +02:00
parent 113e91dcc8
commit 8a6b686490
+12 -5
View File
@@ -13,12 +13,16 @@ mod prelude {
use prelude::*; use prelude::*;
use clap::Parser; use clap::Parser;
use std::time::Instant;
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
struct Args { struct Args {
/// Number of threads /// Number of threads
#[clap(short, long, default_value_t = 1)] #[clap(short, long, default_value_t = 1)]
threads: usize, threads: usize,
/// Display stats after each propagation
#[clap(short, long)]
display: bool,
} }
fn main() { fn main() {
@@ -37,18 +41,21 @@ 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_new(Some(args.threads)); stats = population.propagate_new(Some(args.threads));
//population.display(); //population.display();
println!( if args.display {
"Normal: {} Infecteds: {} Immunes: {} Deads: {}", println!(
stats[0], stats[1], stats[2], stats[3] "Normal: {} Infecteds: {} Immunes: {} Deads: {}",
); stats[0], stats[1], stats[2], stats[3]
);
}
if stats[1] == 0 { if stats[1] == 0 {
break; break;
} }
} }
println!("Propagation finished in {} steps", counter); println!("Propagation finished in {} steps, {:?}", counter, now.elapsed());
//population.display(); //population.display();
} }