Die Welt nannte 'pokerfreak' nur noch in zwei Harness-Zeilen - der Rest waren veraltete Rust-Pruefungen im Pruefordner, die der Aufbau nie auffrischte.
88 lines
2.8 KiB
Rust
88 lines
2.8 KiB
Rust
//! Is the engine better or worse than before? Plays the fixed scenarios of `sim::benchmark` and
|
|
//! compares them deal by deal with the saved baseline. Exit code 1 on a regression.
|
|
//!
|
|
//! ```text
|
|
//! cargo run --release --bin benchmark # compare with benchmarks/baseline.txt
|
|
//! cargo run --release --bin benchmark -- --save # the current engine becomes the baseline
|
|
//! ```
|
|
|
|
use rechner::sim::benchmark::{parse, render, run_all, verdict_of_run, Report};
|
|
use rechner::sim::paired::{Comparison, Verdict};
|
|
use std::process::{exit, Command};
|
|
use std::time::Instant;
|
|
use std::{env, fs};
|
|
|
|
const BASELINE: &str = "benchmarks/baseline.txt";
|
|
|
|
fn git(args: &[&str]) -> String {
|
|
Command::new("git")
|
|
.args(args)
|
|
.output()
|
|
.map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string())
|
|
.unwrap_or_default()
|
|
}
|
|
|
|
/// The commit, marked when the working tree differs from it.
|
|
fn version() -> String {
|
|
let dirty = if git(&["status", "--porcelain"]).is_empty() { "" } else { "+lokal" };
|
|
format!("{}{dirty}", git(&["rev-parse", "--short", "HEAD"]))
|
|
}
|
|
|
|
fn word(verdict: Verdict) -> &'static str {
|
|
match verdict {
|
|
Verdict::Identical => "gleich",
|
|
Verdict::Better => "BESSER",
|
|
Verdict::Worse => "SCHLECHTER",
|
|
Verdict::Unclear => "nicht unterscheidbar",
|
|
}
|
|
}
|
|
|
|
fn line(name: &str, c: &Comparison) -> String {
|
|
format!("{name:<26} {:>+8.2} ± {:>6.2} bb/100 {:>5} geändert {}", c.delta_bb_per_100, c.ci95, c.changed_deals, word(c.verdict))
|
|
}
|
|
|
|
fn print_report(report: &Report) {
|
|
for (name, c) in &report.scenarios {
|
|
println!("{}", line(name, c));
|
|
}
|
|
println!("{}", line("GESAMT", &report.overall));
|
|
if report.invalid > 0 {
|
|
println!("{} ungültige Anfragen: Fehler im Simulator oder der Prüfung", report.invalid);
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let save = env::args().any(|a| a == "--save");
|
|
let started = Instant::now();
|
|
let run = run_all(&version());
|
|
for s in &run.scenarios {
|
|
println!("{:<26} {:>+9.2} bb/100 {:>6} Entscheidungen {:>4} ABSTAIN", s.name, s.bb_per_100(), s.decisions, s.abstains);
|
|
}
|
|
println!("{} in {:.0} s\n", run.label, started.elapsed().as_secs_f64());
|
|
if save {
|
|
if let Err(e) = fs::write(BASELINE, render(&run)) {
|
|
eprintln!("{BASELINE}: {e}");
|
|
exit(2);
|
|
}
|
|
println!("Basislinie gespeichert: {BASELINE}");
|
|
return;
|
|
}
|
|
let base = fs::read_to_string(BASELINE).map_err(|e| format!("{BASELINE}: {e}")).and_then(|t| parse(&t));
|
|
let report = base.and_then(|b| {
|
|
println!("gegen Basislinie {}", b.label);
|
|
verdict_of_run(&b, &run)
|
|
});
|
|
match report {
|
|
Ok(report) => {
|
|
print_report(&report);
|
|
if report.has_regression() {
|
|
exit(1);
|
|
}
|
|
}
|
|
Err(e) => {
|
|
eprintln!("{e}");
|
|
exit(2);
|
|
}
|
|
}
|
|
}
|