generated from PlexSheep/rs-base
Compare commits
No commits in common. "0cd46eb2debd947d50989024cc57ac45269cee17" and "274a6026b4676e33bb8591390cd36f504d0aac08" have entirely different histories.
0cd46eb2de
...
274a6026b4
4 changed files with 16 additions and 15 deletions
|
@ -36,6 +36,7 @@ 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"
|
||||||
|
|
|
@ -2,7 +2,6 @@ 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;
|
||||||
|
@ -66,8 +65,4 @@ where
|
||||||
fn is_finished(&self) -> bool {
|
fn is_finished(&self) -> bool {
|
||||||
self.finished
|
self.finished
|
||||||
}
|
}
|
||||||
fn start(&self) -> WResult<()> {
|
|
||||||
todo!();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,9 @@ 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
|
||||||
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 report = self.report_shared();
|
||||||
let this = std::sync::Arc::new(self);
|
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
|
// 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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,11 @@
|
||||||
// #![warn(missing_docs)]
|
// #![warn(missing_docs)]
|
||||||
#![warn(missing_debug_implementations)]
|
#![warn(missing_debug_implementations)]
|
||||||
|
|
||||||
use std::thread::sleep_ms;
|
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;
|
||||||
|
@ -45,7 +46,8 @@ struct Cli {
|
||||||
threads: usize,
|
threads: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
#[tokio::main]
|
||||||
|
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,15 +65,17 @@ 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:#?}");
|
||||||
|
|
||||||
bench.start()?;
|
let n = cli.n;
|
||||||
|
let in_progress_bench = tokio::spawn( async move {
|
||||||
|
bench.bench(n)
|
||||||
|
});
|
||||||
|
|
||||||
loop {
|
while !bench.is_finished() {
|
||||||
sleep_ms(1000);
|
tokio::time::sleep(tokio::time::Duration::from_millis(5000)).await;
|
||||||
println!("{}", bench.report());
|
println!("{}", bench.report());
|
||||||
if bench.is_finished() {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
in_progress_bench.await;
|
||||||
|
dbg!(bench.report());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue