i think i have decided on the api
cargo devel CI / cargo CI (push) Successful in 1m37s Details

This commit is contained in:
Christoph J. Scherr 2024-04-18 14:59:53 +02:00
parent b4fa88eab5
commit 0cd46eb2de
4 changed files with 16 additions and 16 deletions

View File

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

View File

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

View File

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

View File

@ -2,9 +2,10 @@
// #![warn(missing_docs)] // #![warn(missing_docs)]
#![warn(missing_debug_implementations)] #![warn(missing_debug_implementations)]
use std::thread::sleep_ms;
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;
@ -44,8 +45,7 @@ struct Cli {
threads: usize, threads: usize,
} }
#[tokio::main] fn main() -> anyhow::Result<()> {
async fn main() -> anyhow::Result<()> {
let cli = Cli::parse(); let cli = Cli::parse();
if cli.verbose { if cli.verbose {
Logger::build_mini(Some(Level::DEBUG))?; Logger::build_mini(Some(Level::DEBUG))?;
@ -63,18 +63,15 @@ 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:#?}");
let n = cli.n; bench.start()?;
let bench2 = bench.clone();
let in_progress_bench = tokio::spawn(async move {
bench2.bench(n).await
});
while !bench.is_finished() { loop {
tokio::time::sleep(tokio::time::Duration::from_millis(5000)).await; sleep_ms(1000);
println!("{}", bench.report()); println!("{}", bench.report());
if bench.is_finished() {
break;
}
} }
in_progress_bench.await;
dbg!(bench.report());
Ok(()) Ok(())
} }