Skip to main content

forge/
sim.rs

1//! Shared simulation helpers used by bench, items, and compare runners.
2
3use anyhow::{Context, Result};
4use prost::Message;
5use wowlab_engine_ports::{ChunkAssignment, ChunkReport};
6use wowlab_types::proto::ChunkTelemetry;
7
8use crate::constants::DPS_SCALE;
9
10pub(crate) fn make_chunk(label: &str, iterations: u32, chunk_id: Option<&str>) -> ChunkAssignment {
11    let mut chunk = ChunkAssignment::single(label, iterations);
12
13    if let Some(id) = chunk_id {
14        chunk.chunk_id = id.to_string();
15    }
16
17    chunk
18}
19
20pub(crate) fn decode_telemetry(report: &ChunkReport) -> Result<ChunkTelemetry> {
21    ChunkTelemetry::decode(report.telemetry_bytes.as_slice())
22        .context("failed to decode ChunkTelemetry")
23}
24
25pub(crate) const fn mean_dps(telemetry: &ChunkTelemetry) -> f64 {
26    telemetry.mean_dps_x10 as f64 / DPS_SCALE
27}