From db79d9299eec6f5bf09146ba44a3a3b925933412 Mon Sep 17 00:00:00 2001 From: Yjn024 Date: Tue, 27 Dec 2022 11:49:59 +0800 Subject: [PATCH] fix timer --- src/main.rs | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/src/main.rs b/src/main.rs index cb9b785..5af4aa6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,9 +4,7 @@ pub mod base; pub mod math; use std::process; -use std::sync::mpsc; -use std::thread; -use std::time::Duration; +use std::time::Instant; use base::Component; use base::Expression; @@ -57,35 +55,19 @@ fn main() { numbers.sort(); - let (tx, rx) = mpsc::channel(); - let (txb, rxb) = mpsc::channel(); - - thread::spawn(move || { - let mut i: u64 = 0; - loop { - if rxb.try_recv().is_ok() { - tx.send(i).unwrap(); - break; - } - thread::sleep(Duration::from_micros(1)); - i += 1; - if rxb.try_recv().is_ok() { - tx.send(i).unwrap(); - break; - } - } - }); - + let start = Instant::now(); let solutions = solve(&numbers, &super_mode, &max); - txb.send(true).unwrap(); - let dur = rx.recv().unwrap(); if solutions.len() == 0 { println!("No solutions found"); } else { for (i, _item) in solutions.iter().enumerate() { println!("{}", solutions[i].to_string()); } - println!("Found {} solutions in {} ms", solutions.len(), (dur as f64) * 0.001); + println!( + "Found {} solutions in {} ms", + solutions.len(), + (start.elapsed().as_micros() as f64) * 0.001 + ); } } }