generated from PlexSheep/rs-base
Compare commits
No commits in common. "2ae53bc4649b71a49dfd3fb8f7f8e5565a0c6c5d" and "2e46abbee0c619c9c9592a59895579daf5e4f48a" have entirely different histories.
2ae53bc464
...
2e46abbee0
5 changed files with 9 additions and 46 deletions
|
@ -24,7 +24,6 @@ serde = ["dep:serde"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.81"
|
anyhow = "1.0.81"
|
||||||
chrono = { version = "0.4.37" }
|
|
||||||
clap = { version = "4.5.3", features = ["derive"], optional = true }
|
clap = { version = "4.5.3", features = ["derive"], optional = true }
|
||||||
colored = { version = "2.1.0", optional = false }
|
colored = { version = "2.1.0", optional = false }
|
||||||
libpt = "0.4.2"
|
libpt = "0.4.2"
|
||||||
|
@ -32,7 +31,6 @@ rand = "0.8.5"
|
||||||
regex = "1.10.3"
|
regex = "1.10.3"
|
||||||
serde = { version = "1.0.197", optional = true, features = ["serde_derive"] }
|
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"
|
|
||||||
thiserror = "1.0.58"
|
thiserror = "1.0.58"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
|
|
|
@ -11,12 +11,8 @@ pub struct BuiltinBenchmark<'wl, WL: WordList, SL: Solver<'wl, WL>> {
|
||||||
builder: GameBuilder<'wl, WL>,
|
builder: GameBuilder<'wl, WL>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'wl, WL, SL> Benchmark<'wl, WL, SL> for BuiltinBenchmark<'wl, WL, SL>
|
impl<'wl, WL: WordList, SL: Solver<'wl, WL>> Benchmark<'wl, WL, SL>
|
||||||
where
|
for BuiltinBenchmark<'wl, WL, SL>
|
||||||
WL: WordList,
|
|
||||||
WL: 'wl,
|
|
||||||
SL: Solver<'wl, WL>,
|
|
||||||
SL: 'wl,
|
|
||||||
{
|
{
|
||||||
fn build(wordlist: &'wl WL, solver: SL) -> crate::error::WResult<Self> {
|
fn build(wordlist: &'wl WL, solver: SL) -> crate::error::WResult<Self> {
|
||||||
let builder: GameBuilder<_> = Game::builder(wordlist);
|
let builder: GameBuilder<_> = Game::builder(wordlist);
|
||||||
|
|
|
@ -19,7 +19,6 @@ where
|
||||||
WL: WordList,
|
WL: WordList,
|
||||||
WL: 'wl,
|
WL: 'wl,
|
||||||
SL: Solver<'wl, WL>,
|
SL: Solver<'wl, WL>,
|
||||||
SL: 'wl,
|
|
||||||
{
|
{
|
||||||
fn build(wordlist: &'wl WL, solver: SL) -> WResult<Self>;
|
fn build(wordlist: &'wl WL, solver: SL) -> WResult<Self>;
|
||||||
fn builder(&'wl self) -> &'wl GameBuilder<'wl, WL>;
|
fn builder(&'wl self) -> &'wl GameBuilder<'wl, WL>;
|
||||||
|
@ -28,12 +27,16 @@ where
|
||||||
}
|
}
|
||||||
fn solver(&'wl self) -> &'wl SL;
|
fn solver(&'wl self) -> &'wl SL;
|
||||||
fn play(&'wl self) -> WResult<GuessResponse> {
|
fn play(&'wl self) -> WResult<GuessResponse> {
|
||||||
self.solver().play(&mut self.make_game()?)
|
// FIXME: wth why does the lifetime break here?
|
||||||
|
let mut game: Game<'wl, WL> = self.make_game()?;
|
||||||
|
|
||||||
|
todo!()
|
||||||
}
|
}
|
||||||
fn bench(&'wl self, n: usize) -> WResult<Report> {
|
fn bench(&'wl self, n: usize) -> WResult<Report> {
|
||||||
// PERF: it would be better to make this multithreaded
|
// PERF: it would be better to make this multithreaded
|
||||||
let part = n / 20;
|
let part = n / 20;
|
||||||
let mut report = Report::new();
|
let mut report = Report::new();
|
||||||
|
let start = std::time::Instant::now();
|
||||||
|
|
||||||
for i in 0..n {
|
for i in 0..n {
|
||||||
// TODO: limit execution time for the following, perhaps async
|
// TODO: limit execution time for the following, perhaps async
|
||||||
|
@ -43,8 +46,6 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
report.finalize();
|
|
||||||
|
|
||||||
Ok(report)
|
Ok(report)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use chrono::{self, NaiveDateTime, NaiveTime, TimeDelta};
|
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
|
@ -7,24 +6,14 @@ use serde::{Deserialize, Serialize};
|
||||||
use crate::game::response::GuessResponse;
|
use crate::game::response::GuessResponse;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct Report {
|
pub struct Report {
|
||||||
data: Vec<GuessResponse>,
|
data: Vec<GuessResponse>,
|
||||||
start: NaiveDateTime,
|
|
||||||
end: Option<NaiveDateTime>,
|
|
||||||
benchtime: Option<TimeDelta>,
|
|
||||||
/// is the benchmark finished?
|
|
||||||
finished: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Report {
|
impl Report {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self { data: Vec::new() }
|
||||||
data: Vec::new(),
|
|
||||||
start: chrono::Local::now().naive_local(),
|
|
||||||
benchtime: None,
|
|
||||||
end: None,
|
|
||||||
finished: false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pub fn add(&mut self, data: GuessResponse) {
|
pub fn add(&mut self, data: GuessResponse) {
|
||||||
self.data.push(data)
|
self.data.push(data)
|
||||||
|
@ -41,23 +30,6 @@ impl Report {
|
||||||
pub fn avg_score(&self) -> usize {
|
pub fn avg_score(&self) -> usize {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// finalize the record
|
|
||||||
///
|
|
||||||
/// Sets the [benchtime](Report::benchtime) and [over](Report::over). In future versions, this
|
|
||||||
/// method might be used to precompute statistical information from the data.
|
|
||||||
pub(crate) fn finalize(&mut self) {
|
|
||||||
self.end = Some(chrono::Local::now().naive_local());
|
|
||||||
self.benchtime = Some(self.end.unwrap() - self.start);
|
|
||||||
self.finished = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// is the report finished?
|
|
||||||
///
|
|
||||||
/// Will be true after the [benchmark][super::Benchmark] is done.
|
|
||||||
pub fn finished(&self) -> bool {
|
|
||||||
self.finished
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Report {
|
impl Display for Report {
|
||||||
|
|
|
@ -58,10 +58,6 @@ fn main() -> anyhow::Result<()> {
|
||||||
println!("word length: must be {} long but is {}", game.length(), len);
|
println!("word length: must be {} long but is {}", game.length(), len);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
GameError::WordNotInWordlist(w) => {
|
|
||||||
println!("bad word: word \"{w}\" is not in the wordlist",);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
_ => {
|
_ => {
|
||||||
return Err(err.into());
|
return Err(err.into());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue