Skip to content

Commit 3fdbda3

Browse files
Support Component-less Runtime Benchmarks (#6645)
* Update benchmarking macro for no components * Handle output when error * skip when empty * Update analysis for zero components * add back trace logs * Apply suggestions from code review * remove mean value, and use median value * Add note * Use standard for loop * Apply suggestions from code review Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
1 parent 67929b9 commit 3fdbda3

File tree

3 files changed

+307
-224
lines changed

3 files changed

+307
-224
lines changed

src/analysis.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,35 @@ pub enum BenchmarkSelector {
3737
}
3838

3939
impl Analysis {
40+
// Useful for when there are no components, and we just need an median value of the benchmark results.
41+
// Note: We choose the median value because it is more robust to outliers.
42+
fn median_value(r: &Vec<BenchmarkResults>, selector: BenchmarkSelector) -> Option<Self> {
43+
if r.is_empty() { return None }
44+
45+
let mut values: Vec<u128> = r.iter().map(|result|
46+
match selector {
47+
BenchmarkSelector::ExtrinsicTime => result.extrinsic_time,
48+
BenchmarkSelector::StorageRootTime => result.storage_root_time,
49+
BenchmarkSelector::Reads => result.reads.into(),
50+
BenchmarkSelector::Writes => result.writes.into(),
51+
}
52+
).collect();
53+
54+
values.sort();
55+
let mid = values.len() / 2;
56+
57+
Some(Self {
58+
base: values[mid],
59+
slopes: Vec::new(),
60+
names: Vec::new(),
61+
value_dists: None,
62+
model: None,
63+
})
64+
}
65+
4066
pub fn median_slopes(r: &Vec<BenchmarkResults>, selector: BenchmarkSelector) -> Option<Self> {
67+
if r[0].components.is_empty() { return Self::median_value(r, selector) }
68+
4169
let results = r[0].components.iter().enumerate().map(|(i, &(param, _))| {
4270
let mut counted = BTreeMap::<Vec<u32>, usize>::new();
4371
for result in r.iter() {
@@ -114,6 +142,8 @@ impl Analysis {
114142
}
115143

116144
pub fn min_squares_iqr(r: &Vec<BenchmarkResults>, selector: BenchmarkSelector) -> Option<Self> {
145+
if r[0].components.is_empty() { return Self::median_value(r, selector) }
146+
117147
let mut results = BTreeMap::<Vec<u32>, Vec<u128>>::new();
118148
for result in r.iter() {
119149
let p = result.components.iter().map(|x| x.1).collect::<Vec<_>>();

0 commit comments

Comments
 (0)