From dd5b06e622c6c5c301a1554286ec1f4995c7daca Mon Sep 17 00:00:00 2001 From: Andrei Eres <eresav@me.com> Date: Thu, 25 Apr 2024 17:06:37 +0200 Subject: [PATCH] [subsystem-benchmarks] Log standart deviation for subsystem-benchmarks (#4285) Should help us to understand more what's happening between individual runs and possibly adjust the number of runs --- polkadot/node/subsystem-bench/src/lib/usage.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/polkadot/node/subsystem-bench/src/lib/usage.rs b/polkadot/node/subsystem-bench/src/lib/usage.rs index 59296746ec3..bfaac3265a2 100644 --- a/polkadot/node/subsystem-bench/src/lib/usage.rs +++ b/polkadot/node/subsystem-bench/src/lib/usage.rs @@ -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 @@ -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() +} -- GitLab