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};
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct BuiltinBenchmark<'wl, WL: WordList, SL: Solver<'wl, WL>> {
solver: SL,
builder: GameBuilder<'wl, WL>,
report: Arc<RwLock<Report>>,
finished: bool
}
impl<'wl, WL, SL> Benchmark<'wl, WL, SL> for BuiltinBenchmark<'wl, WL, SL>
@ -38,6 +39,7 @@ where
solver,
report: Arc::new(RwLock::new(Report::new(builder.build()?))),
builder,
finished: false
})
}
fn solver(&self) -> SL {
@ -60,4 +62,7 @@ where
fn report(&'wl self) -> super::Report {
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]
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
WL: WordList,
WL: 'wl,
@ -68,4 +68,5 @@ where
// PERF: Somehow returning &Report would be better as we don't need to clone then
fn report(&'wl self) -> 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 libpt::log::*;
use tokio;
use wordle_analyzer::bench::builtin::BuiltinBenchmark;
use wordle_analyzer::bench::report::Report;
@ -64,31 +65,17 @@ async fn main() -> anyhow::Result<()> {
let bench = BuiltinBenchmark::build(&wl, solver, builder, cli.threads)?;
trace!("{bench:#?}");
loop {
match tokio::time::timeout(
tokio::time::Duration::from_millis(10),
bench.bench(cli.n),
)
.await
{
Ok(result) => {
match result {
Ok(final_report) => {
println!("{}", final_report);
}
Err(err) => {
error!("error while benchmarking: {err:#?}");
}
}
break;
}
Err(_timeout) => {
println!("{}", bench.report());
}
}
}
let n = cli.n;
let in_progress_bench = tokio::spawn( async move {
bench.bench(n)
});
while !bench.is_finished() {
tokio::time::sleep(tokio::time::Duration::from_millis(5000)).await;
println!("{}", bench.report());
}
in_progress_bench.await;
dbg!(bench.report());
// FIXME: Rustc thinks wl is borrowed at this point, but it is not!!!!! Or at least it should
// not be
Ok(())
}