its a mess
cargo devel CI / cargo CI (push) Failing after 1m11s Details

This commit is contained in:
Christoph J. Scherr 2024-04-17 15:01:32 +02:00
parent 628c5163a5
commit 274a6026b4
3 changed files with 20 additions and 27 deletions

View File

@ -8,11 +8,12 @@ use crate::wlist::WordList;
use super::{Benchmark, Report}; use super::{Benchmark, Report};
#[derive(Debug)] #[derive(Debug, Clone)]
pub struct BuiltinBenchmark<'wl, WL: WordList, SL: Solver<'wl, WL>> { pub struct BuiltinBenchmark<'wl, WL: WordList, SL: Solver<'wl, WL>> {
solver: SL, solver: SL,
builder: GameBuilder<'wl, WL>, builder: GameBuilder<'wl, WL>,
report: Arc<RwLock<Report>>, report: Arc<RwLock<Report>>,
finished: bool
} }
impl<'wl, WL, SL> Benchmark<'wl, WL, SL> for BuiltinBenchmark<'wl, WL, SL> impl<'wl, WL, SL> Benchmark<'wl, WL, SL> for BuiltinBenchmark<'wl, WL, SL>
@ -38,6 +39,7 @@ where
solver, solver,
report: Arc::new(RwLock::new(Report::new(builder.build()?))), report: Arc::new(RwLock::new(Report::new(builder.build()?))),
builder, builder,
finished: false
}) })
} }
fn solver(&self) -> SL { fn solver(&self) -> SL {
@ -60,4 +62,7 @@ where
fn report(&'wl self) -> super::Report { fn report(&'wl self) -> super::Report {
self.report.read().expect("lock is poisoned").clone() self.report.read().expect("lock is poisoned").clone()
} }
fn is_finished(&self) -> bool {
self.finished
}
} }

View File

@ -18,7 +18,7 @@ pub mod builtin;
/// Default amount of games to play for a [Benchmark] /// Default amount of games to play for a [Benchmark]
pub const DEFAULT_N: usize = 50; pub const DEFAULT_N: usize = 50;
pub trait Benchmark<'wl, WL, SL>: Sized + Debug + Sync pub trait Benchmark<'wl, WL, SL>: Sized + Debug + Sync + Clone
where where
WL: WordList, WL: WordList,
WL: 'wl, WL: 'wl,
@ -68,4 +68,5 @@ where
// PERF: Somehow returning &Report would be better as we don't need to clone then // PERF: Somehow returning &Report would be better as we don't need to clone then
fn report(&'wl self) -> Report; fn report(&'wl self) -> Report;
fn report_shared(&'wl self) -> Arc<RwLock<Report>>; fn report_shared(&'wl self) -> Arc<RwLock<Report>>;
fn is_finished(&self) -> bool;
} }

View File

@ -6,6 +6,7 @@ use std::sync::Arc;
use clap::Parser; use clap::Parser;
use libpt::log::*; use libpt::log::*;
use tokio;
use wordle_analyzer::bench::builtin::BuiltinBenchmark; use wordle_analyzer::bench::builtin::BuiltinBenchmark;
use wordle_analyzer::bench::report::Report; use wordle_analyzer::bench::report::Report;
@ -64,31 +65,17 @@ async fn main() -> anyhow::Result<()> {
let bench = BuiltinBenchmark::build(&wl, solver, builder, cli.threads)?; let bench = BuiltinBenchmark::build(&wl, solver, builder, cli.threads)?;
trace!("{bench:#?}"); trace!("{bench:#?}");
loop { let n = cli.n;
match tokio::time::timeout( let in_progress_bench = tokio::spawn( async move {
tokio::time::Duration::from_millis(10), bench.bench(n)
bench.bench(cli.n), });
)
.await while !bench.is_finished() {
{ tokio::time::sleep(tokio::time::Duration::from_millis(5000)).await;
Ok(result) => { println!("{}", bench.report());
match result { }
Ok(final_report) => { in_progress_bench.await;
println!("{}", final_report); dbg!(bench.report());
}
Err(err) => {
error!("error while benchmarking: {err:#?}");
}
}
break;
}
Err(_timeout) => {
println!("{}", bench.report());
}
}
}
// FIXME: Rustc thinks wl is borrowed at this point, but it is not!!!!! Or at least it should
// not be
Ok(()) Ok(())
} }