MCPcopy Create free account
hub / github.com/CodSpeedHQ/codspeed / from_runtime_data

Method from_runtime_data

crates/runner-shared/src/walltime_results/stats.rs:8–102  ·  view source on GitHub ↗

Create a WalltimeBenchmark from runtime data. Stats computations are designed to match pytest-codspeed's behavior.

(
        name: String,
        uri: String,
        iters_per_round: Vec<u128>,
        times_per_round_ns: Vec<u128>,
        _max_time_ns: Option<u128>,
    )

Source from the content-addressed store, hash-verified

6 /// Create a WalltimeBenchmark from runtime data.
7 /// Stats computations are designed to match pytest-codspeed's behavior.
8 pub fn from_runtime_data(
9 name: String,
10 uri: String,
11 iters_per_round: Vec<u128>,
12 times_per_round_ns: Vec<u128>,
13 _max_time_ns: Option<u128>,
14 ) -> Self {
15 // Calculate total time in ⚠️ seconds ⚠️
16 let total_time_s = times_per_round_ns.iter().sum::<u128>() as f64 / 1_000_000_000.0;
17
18 // Calculate statistics
19 let times_per_iteration_per_round_ns_sorted: Vec<_> = times_per_round_ns
20 .into_iter()
21 .zip(&iters_per_round)
22 .map(|(time_per_round, iter_per_round)| time_per_round / iter_per_round)
23 .map(|t| t as f64)
24 .sorted_by(|a, b| a.partial_cmp(b).unwrap())
25 .collect::<Vec<f64>>();
26
27 let rounds = times_per_iteration_per_round_ns_sorted.len();
28 let mean_ns = if rounds > 0 {
29 times_per_iteration_per_round_ns_sorted.iter().sum::<f64>() / rounds as f64
30 } else {
31 0.0
32 };
33
34 let min_ns = times_per_iteration_per_round_ns_sorted
35 .first()
36 .copied()
37 .unwrap_or(0.0);
38 let max_ns = times_per_iteration_per_round_ns_sorted
39 .last()
40 .copied()
41 .unwrap_or(0.0);
42
43 // Calculate percentiles
44 let median_ns = if rounds > 0 {
45 let mid = rounds / 2;
46 if rounds % 2 == 0 {
47 (times_per_iteration_per_round_ns_sorted[mid - 1]
48 + times_per_iteration_per_round_ns_sorted[mid])
49 / 2.0
50 } else {
51 times_per_iteration_per_round_ns_sorted[mid]
52 }
53 } else {
54 0.0
55 };
56
57 let q1_ns = quantile(&times_per_iteration_per_round_ns_sorted, 0.25);
58 let q3_ns = quantile(&times_per_iteration_per_round_ns_sorted, 0.75);
59 let stdev_ns = sample_stdev(&times_per_iteration_per_round_ns_sorted, mean_ns);
60
61 // Calculate outliers (simplified - using IQR method)
62 let iqr = q3_ns - q1_ns;
63 let lower_bound = q1_ns - 1.5 * iqr;
64 let upper_bound = q3_ns + 1.5 * iqr;
65 let iqr_outlier_rounds = times_per_iteration_per_round_ns_sorted

Callers

nothing calls this directly

Calls 3

quantileFunction · 0.85
sample_stdevFunction · 0.85
is_emptyMethod · 0.45

Tested by

no test coverage detected