display time take
This commit is contained in:
+8
-1
@@ -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();
|
||||||
|
if args.display {
|
||||||
println!(
|
println!(
|
||||||
"Normal: {} Infecteds: {} Immunes: {} Deads: {}",
|
"Normal: {} Infecteds: {} Immunes: {} Deads: {}",
|
||||||
stats[0], stats[1], stats[2], stats[3]
|
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();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user