Skip to content

Commit

Permalink
fix timer
Browse files Browse the repository at this point in the history
  • Loading branch information
JieningYu committed Dec 27, 2022
1 parent 86d362c commit db79d92
Showing 1 changed file with 7 additions and 25 deletions.
32 changes: 7 additions & 25 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
);
}
}
}
Expand Down

0 comments on commit db79d92

Please sign in to comment.