Skip to main content

forge/bench/
types.rs

1//! Data types for benchmark runs and history.
2
3#[cfg(test)]
4use googletest::{Result as GtestResult, prelude::*};
5use serde::{Deserialize, Serialize};
6use wowlab_common::sys::OsProfile;
7
8#[derive(Clone, Debug, Deserialize, Serialize)]
9pub(crate) struct SpecBenchResult {
10    pub slug: String,
11    pub iterations: u32,
12    pub duration_secs: u32,
13    pub elapsed_ms: u64,
14    pub iterations_per_sec: f64,
15    pub mean_dps: f64,
16}
17
18#[derive(Clone, Debug, Deserialize, Serialize)]
19pub(crate) struct ScalingPoint {
20    pub threads: usize,
21    pub elapsed_ms: u64,
22    pub iterations_per_sec: f64,
23    pub multiplier: f64,
24    pub efficiency: f64,
25    pub marginal_gain: f64,
26    pub is_p_core_range: bool,
27}
28
29#[derive(Clone, Debug, Deserialize, Serialize)]
30pub(crate) struct ScalingResult {
31    pub slug: String,
32    pub iterations: u32,
33    pub points: Vec<ScalingPoint>,
34}
35
36#[derive(Clone, Debug, Deserialize, Serialize)]
37pub(crate) struct BenchRun {
38    pub engine_version: String,
39    pub timestamp: String,
40    pub git_hash: String,
41    pub git_branch: String,
42    pub rustc_version: String,
43    pub system: OsProfile,
44    pub results: Vec<SpecBenchResult>,
45    #[serde(default)]
46    pub scaling: Vec<ScalingResult>,
47}
48
49#[derive(Clone, Debug, Deserialize, Serialize)]
50pub(crate) struct BenchHistory {
51    pub runs: Vec<BenchRun>,
52}
53
54#[cfg(test)]
55mod tests {
56    use super::*;
57
58    #[gtest]
59    fn spec_result_json_preserves_the_persisted_run_fields() -> GtestResult<()> {
60        let result = SpecBenchResult {
61            slug: "fire_mage".to_string(),
62            iterations: 17,
63            duration_secs: 45,
64            elapsed_ms: 123,
65            iterations_per_sec: 138.2,
66            mean_dps: 456.7,
67        };
68
69        verify_that!(
70            serde_json::to_value(result).or_fail()?,
71            eq(&serde_json::json!({
72                "slug": "fire_mage",
73                "iterations": 17,
74                "duration_secs": 45,
75                "elapsed_ms": 123,
76                "iterations_per_sec": 138.2,
77                "mean_dps": 456.7,
78            }))
79        )?;
80
81        Ok(())
82    }
83}