wordle-analyzer/src/bin/bench/cli.rs

87 lines
2.8 KiB
Rust
Raw Permalink Normal View History

2024-03-26 00:16:26 +01:00
#![warn(clippy::all)]
// #![warn(missing_docs)]
#![warn(missing_debug_implementations)]
2024-07-24 12:01:14 +02:00
use std::thread::sleep;
2024-04-18 14:59:53 +02:00
2024-03-26 00:16:26 +01:00
use clap::Parser;
use libpt::log::*;
2024-04-04 22:46:25 +02:00
use wordle_analyzer::bench::builtin::BuiltinBenchmark;
use wordle_analyzer::bench::{Benchmark, DEFAULT_N};
2024-04-17 12:39:14 +02:00
use wordle_analyzer::game::GameBuilder;
2024-07-24 12:01:14 +02:00
use wordle_analyzer::solve::{AnyBuiltinSolver, BuiltinSolverNames};
2024-03-26 00:16:26 +01:00
use wordle_analyzer::wlist::builtin::BuiltinWList;
2024-04-04 20:14:20 +02:00
2024-03-26 00:16:26 +01:00
use wordle_analyzer::{self, game};
#[derive(Parser, Clone, Debug)]
#[command(version, about, long_about, author)]
struct Cli {
/// precompute all possibilities for better performance at runtime
#[arg(short, long)]
precompute: bool,
/// how long should the word be?
#[arg(short, long, default_value_t = wordle_analyzer::DEFAULT_WORD_LENGTH)]
length: usize,
/// how many times can we guess?
#[arg(short, long, default_value_t = wordle_analyzer::DEFAULT_MAX_STEPS)]
max_steps: usize,
/// more verbose logs
#[arg(short, long)]
verbose: bool,
/// which solver to use
#[arg(short, long, default_value_t = BuiltinSolverNames::default())]
solver: BuiltinSolverNames,
2024-04-04 22:46:25 +02:00
/// how many games to play for the benchmark
#[arg(short, long, default_value_t = DEFAULT_N)]
n: usize,
/// how many threads to use for benchmarking
///
/// Note that the application as the whole will use at least one more thread.
#[arg(short, long, default_value_t = num_cpus::get())]
threads: usize,
/// select a wordlist
///
/// 'ger' and 'eng' are special values bundled with this executable, if the value does not
/// match either of those, it will be assumed to be a file path.
#[arg(short, long, default_value_t = String::from("eng"))]
wordlist: String,
2024-03-26 00:16:26 +01:00
}
2024-04-18 14:59:53 +02:00
fn main() -> anyhow::Result<()> {
2024-03-26 00:16:26 +01:00
let cli = Cli::parse();
if cli.verbose {
Logger::builder().set_level(Level::DEBUG).build().unwrap();
2024-03-26 00:16:26 +01:00
} else {
Logger::builder().set_level(Level::INFO).build().unwrap();
2024-03-26 00:16:26 +01:00
}
2024-04-04 22:46:25 +02:00
trace!("dumping CLI: {:#?}", cli);
2024-03-26 00:16:26 +01:00
let wl = match cli.wordlist.as_str() {
"ger" => BuiltinWList::german(cli.length),
"eng" => BuiltinWList::english(cli.length),
_ => BuiltinWList::load(&cli.wordlist, cli.length)?,
};
2024-04-17 12:39:14 +02:00
let builder: GameBuilder<'_, BuiltinWList> = game::Game::builder(&wl)
2024-03-26 00:16:26 +01:00
.length(cli.length)
.max_steps(cli.max_steps)
.precompute(cli.precompute);
2024-04-17 12:39:14 +02:00
let solver: AnyBuiltinSolver<'_, BuiltinWList> = cli.solver.to_solver(&wl);
2024-04-17 14:13:48 +02:00
let bench = BuiltinBenchmark::build(&wl, solver, builder, cli.threads)?;
2024-04-04 22:46:25 +02:00
trace!("{bench:#?}");
2024-07-31 10:25:03 +02:00
bench.start(cli.n, &bench.builder())?;
2024-04-17 15:01:32 +02:00
2024-04-18 14:59:53 +02:00
loop {
2024-07-24 12:01:14 +02:00
sleep(std::time::Duration::from_secs(1));
2024-04-17 15:01:32 +02:00
println!("{}", bench.report());
2024-04-18 14:59:53 +02:00
if bench.is_finished() {
break;
}
}
2024-03-26 00:16:26 +01:00
Ok(())
}