Skip to content

Commit

Permalink
Always sort exported results (fixes sharkdp#601)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
  • Loading branch information
SUPERCILEX committed Jan 7, 2023
1 parent 4fe8db4 commit 9be7c06
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 35 deletions.
58 changes: 29 additions & 29 deletions src/benchmark/relative_speed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,33 @@ pub fn compute(results: &[BenchmarkResult]) -> Option<Vec<BenchmarkResultWithRel
return None;
}

Some(
results
.iter()
.map(|result| {
let ratio = result.mean / fastest.mean;

// https://en.wikipedia.org/wiki/Propagation_of_uncertainty#Example_formulas
// Covariance asssumed to be 0, i.e. variables are assumed to be independent
let ratio_stddev = match (result.stddev, fastest.stddev) {
(Some(result_stddev), Some(fastest_stddev)) => Some(
ratio
* ((result_stddev / result.mean).powi(2)
+ (fastest_stddev / fastest.mean).powi(2))
.sqrt(),
),
_ => None,
};

BenchmarkResultWithRelativeSpeed {
result,
relative_speed: ratio,
relative_speed_stddev: ratio_stddev,
is_fastest: result == fastest,
}
})
.collect(),
)
let mut results = results
.iter()
.map(|result| {
let ratio = result.mean / fastest.mean;

// https://en.wikipedia.org/wiki/Propagation_of_uncertainty#Example_formulas
// Covariance asssumed to be 0, i.e. variables are assumed to be independent
let ratio_stddev = match (result.stddev, fastest.stddev) {
(Some(result_stddev), Some(fastest_stddev)) => Some(
ratio
* ((result_stddev / result.mean).powi(2)
+ (fastest_stddev / fastest.mean).powi(2))
.sqrt(),
),
_ => None,
};

BenchmarkResultWithRelativeSpeed {
result,
relative_speed: ratio,
relative_speed_stddev: ratio_stddev,
is_fastest: result == fastest,
}
})
.collect::<Vec<_>>();
results.sort_by(|l, r| compare_mean_time(l.result, r.result));
Some(results)
}

#[cfg(test)]
Expand Down Expand Up @@ -85,8 +85,8 @@ fn test_compute_relative_speed() {

let annotated_results = compute(&results).unwrap();

assert_relative_eq!(1.5, annotated_results[0].relative_speed);
assert_relative_eq!(1.0, annotated_results[1].relative_speed);
assert_relative_eq!(1.0, annotated_results[0].relative_speed);
assert_relative_eq!(1.5, annotated_results[1].relative_speed);
assert_relative_eq!(2.5, annotated_results[2].relative_speed);
}

Expand Down
4 changes: 1 addition & 3 deletions src/benchmark/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ impl<'a> Scheduler<'a> {
return;
}

if let Some(mut annotated_results) = relative_speed::compute(&self.results) {
annotated_results.sort_by(|l, r| relative_speed::compare_mean_time(l.result, r.result));

if let Some(annotated_results) = relative_speed::compute(&self.results) {
let fastest = &annotated_results[0];
let others = &annotated_results[1..];

Expand Down
4 changes: 2 additions & 2 deletions src/export/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ fn test_markdown_format_s() {
let actual = String::from_utf8(exporter.serialize(&timing_results, None).unwrap()).unwrap();
let expect = format!(
"{}\
| `sleep 2` | 2.005 ± 0.002 | 2.002 | 2.008 | 18.97 ± 0.29 |
| `sleep 0.1` | 0.106 ± 0.002 | 0.102 | 0.108 | 1.00 |
| `sleep 2` | 2.005 ± 0.002 | 2.002 | 2.008 | 18.97 ± 0.29 |
",
cfg_test_table_header("s".to_string())
);
Expand Down Expand Up @@ -261,8 +261,8 @@ fn test_markdown_format_time_unit_ms() {
.unwrap();
let expect = format!(
"{}\
| `sleep 2` | 2005.0 ± 2.0 | 2002.0 | 2008.0 | 18.97 ± 0.29 |
| `sleep 0.1` | 105.7 ± 1.6 | 102.3 | 108.0 | 1.00 |
| `sleep 2` | 2005.0 ± 2.0 | 2002.0 | 2008.0 | 18.97 ± 0.29 |
",
cfg_test_table_header("ms".to_string())
);
Expand Down
2 changes: 1 addition & 1 deletion src/export/orgmode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ fn test_orgmode_format_s() {
String::from_utf8(exporter.serialize(&results, Some(Unit::Second)).unwrap()).unwrap();
let expect = format!(
"{}\
| =sleep 2= | 2.005 ± 0.002 | 2.002 | 2.008 | 18.97 ± 0.29 |
| =sleep 0.1= | 0.106 ± 0.002 | 0.102 | 0.108 | 1.00 |
| =sleep 2= | 2.005 ± 0.002 | 2.002 | 2.008 | 18.97 ± 0.29 |
",
cfg_test_table_header("s".to_string())
);
Expand Down

0 comments on commit 9be7c06

Please sign in to comment.