Skip to content

Commit

Permalink
[subsystem-benchmarks] Log standart deviation for subsystem-benchmarks (
Browse files Browse the repository at this point in the history
#4285)

Should help us to understand more what's happening between individual
runs and possibly adjust the number of runs
  • Loading branch information
AndreiEres authored and Morganamilo committed May 2, 2024
1 parent 3838cf6 commit 42c1d1f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions polkadot/node/subsystem-bench/src/lib/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ impl ResourceUsage {
for (resource_name, values) in by_name {
let total = values.iter().map(|v| v.total).sum::<f64>() / values.len() as f64;
let per_block = values.iter().map(|v| v.per_block).sum::<f64>() / values.len() as f64;
let per_block_sd =
standard_deviation(&values.iter().map(|v| v.per_block).collect::<Vec<f64>>());
println!(
"[{}] standart_deviation {:.2}%",
resource_name,
per_block_sd / per_block * 100.0
);
average.push(Self { resource_name, total, per_block });
}
average
Expand All @@ -179,3 +186,11 @@ pub struct ChartItem {
pub unit: String,
pub value: f64,
}

fn standard_deviation(values: &[f64]) -> f64 {
let n = values.len() as f64;
let mean = values.iter().sum::<f64>() / n;
let variance = values.iter().map(|v| (v - mean).powi(2)).sum::<f64>() / (n - 1.0);

variance.sqrt()
}

0 comments on commit 42c1d1f

Please sign in to comment.