Compare commits

..

No commits in common. "0cd46eb2debd947d50989024cc57ac45269cee17" and "274a6026b4676e33bb8591390cd36f504d0aac08" have entirely different histories.

4 changed files with 16 additions and 15 deletions

View file

@ -36,6 +36,7 @@ serde = { version = "1.0.197", optional = true, features = ["serde_derive"] }
serde_json = { version = "1.0.114", optional = true }
# serde_with = "3.7.0"
thiserror = "1.0.58"
tokio = { version = "1.37.0", features = ["macros", "rt", "rt-multi-thread", "time"] }
[[bin]]
name = "wordlec"

View file

@ -2,7 +2,6 @@ use std::sync::{Arc, RwLock};
use libpt::log::info;
use crate::error::WResult;
use crate::game::{self, GameBuilder};
use crate::solve::Solver;
use crate::wlist::WordList;
@ -66,8 +65,4 @@ where
fn is_finished(&self) -> bool {
self.finished
}
fn start(&self) -> WResult<()> {
todo!();
Ok(())
}
}

View file

@ -44,7 +44,9 @@ where
// TODO: add some interface to get reports while the benchmark runs
// TODO: make the benchmark optionally multithreaded
// NOTE: This is blocking, use start to let it run in another thread
fn bench(&'wl self, n: usize) -> WResult<Report> {
// HACK: Shame on me, but I cannot find out how to share the data over threads, so that we can
// make this a start function and just poll records while rayon does the benching.
async fn bench(&'wl self, n: usize) -> WResult<Report> {
let report = self.report_shared();
let this = std::sync::Arc::new(self);
@ -66,6 +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 start(&self) -> WResult<()>;
fn is_finished(&self) -> bool;
}

View file

@ -2,10 +2,11 @@
// #![warn(missing_docs)]
#![warn(missing_debug_implementations)]
use std::thread::sleep_ms;
use std::sync::Arc;
use clap::Parser;
use libpt::log::*;
use tokio;
use wordle_analyzer::bench::builtin::BuiltinBenchmark;
use wordle_analyzer::bench::report::Report;
@ -45,7 +46,8 @@ struct Cli {
threads: usize,
}
fn main() -> anyhow::Result<()> {
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
if cli.verbose {
Logger::build_mini(Some(Level::DEBUG))?;
@ -63,15 +65,17 @@ fn main() -> anyhow::Result<()> {
let bench = BuiltinBenchmark::build(&wl, solver, builder, cli.threads)?;
trace!("{bench:#?}");
bench.start()?;
let n = cli.n;
let in_progress_bench = tokio::spawn( async move {
bench.bench(n)
});
loop {
sleep_ms(1000);
while !bench.is_finished() {
tokio::time::sleep(tokio::time::Duration::from_millis(5000)).await;
println!("{}", bench.report());
if bench.is_finished() {
break;
}
}
in_progress_bench.await;
dbg!(bench.report());
Ok(())
}