mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-02 17:11:28 +00:00
Introduce new BenchmarkRun struct
This commit is contained in:
1 parent
46e1f9f2c1
commit
14d773998a
7 files changed
+247
-264
No files matched your search
@@ -31,9 +31,7 @@ impl BenchmarkResultWithRelativeSpeed<'_> {
|
||||
}
|
||||
|
||||
pub fn compare_mean_time(l: &BenchmarkResult, r: &BenchmarkResult) -> Ordering {
|
||||
l.mean_wall_clock_time()
|
||||
.partial_cmp(&r.mean_wall_clock_time())
|
||||
.unwrap_or(Ordering::Equal)
|
||||
l.mean().partial_cmp(&r.mean()).unwrap_or(Ordering::Equal)
|
||||
}
|
||||
|
||||
pub fn fastest_of(results: &[BenchmarkResult]) -> &BenchmarkResult {
|
||||
@@ -68,11 +66,9 @@ fn compute_relative_speeds<'a>(
|
||||
}
|
||||
|
||||
let ratio = match relative_ordering {
|
||||
Ordering::Less => reference.mean_wall_clock_time() / result.mean_wall_clock_time(),
|
||||
Ordering::Equal => Ratio::new::<quantity::ratio>(1.0),
|
||||
Ordering::Greater => {
|
||||
result.mean_wall_clock_time() / reference.mean_wall_clock_time()
|
||||
}
|
||||
Ordering::Less => reference.mean() / result.mean(),
|
||||
Ordering::Equal => 1.0,
|
||||
Ordering::Greater => result.mean() / reference.mean(),
|
||||
};
|
||||
|
||||
// https://en.wikipedia.org/wiki/Propagation_of_uncertainty#Example_formulas
|
||||
@@ -117,9 +113,7 @@ pub fn compute_with_check_from_reference<'a>(
|
||||
reference: &'a BenchmarkResult,
|
||||
sort_order: SortOrder,
|
||||
) -> Option<Vec<BenchmarkResultWithRelativeSpeed<'a>>> {
|
||||
if fastest_of(results).mean_wall_clock_time() == Time::zero()
|
||||
|| reference.mean_wall_clock_time() == Time::zero()
|
||||
{
|
||||
if fastest_of(results).mean() == 0.0 || reference.mean() == 0.0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -132,7 +126,7 @@ pub fn compute_with_check(
|
||||
) -> Option<Vec<BenchmarkResultWithRelativeSpeed<'_>>> {
|
||||
let fastest = fastest_of(results);
|
||||
|
||||
if fastest.mean_wall_clock_time() == Time::zero() {
|
||||
if fastest.mean() == 0.0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -153,19 +147,18 @@ pub fn compute<'a>(
|
||||
fn create_result(name: &str, mean: f64) -> BenchmarkResult {
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use crate::benchmark::measurement::{Measurement, Measurements};
|
||||
use crate::quantity::{second, Time};
|
||||
use crate::benchmark::benchmark_result::BenchmarkRun;
|
||||
|
||||
BenchmarkResult {
|
||||
command: name.into(),
|
||||
command_with_unused_parameters: name.into(),
|
||||
measurements: Measurements {
|
||||
measurements: vec![Measurement {
|
||||
time_wall_clock: Time::new::<second>(mean),
|
||||
time_user: Time::new::<second>(mean),
|
||||
..Default::default()
|
||||
}],
|
||||
},
|
||||
user: mean,
|
||||
system: 0.0,
|
||||
runs: vec![BenchmarkRun {
|
||||
wall_clock_time: mean,
|
||||
}],
|
||||
memory_usage_byte: None,
|
||||
exit_codes: Vec::new(),
|
||||
parameters: BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user