Skip to main content

PairedTiming

Struct PairedTiming 

Source
pub struct PairedTiming {
    pub a_ns: Vec<f64>,
    pub b_ns: Vec<f64>,
    pub ratios: Vec<f64>,
    pub a_went_first: Vec<bool>,
}
Expand description

Paired per-repetition timings for two implementations of one computation.

a_ns[i] and b_ns[i] were measured adjacent in time within repetition i, in an order chosen by the repetition’s coin flip. ratios[i] is b_ns[i] / a_ns[i], so a value above 1 means A is faster — the same orientation as the hand_over_production token these gates already print.

Fields§

§a_ns: Vec<f64>

Nanoseconds per iteration for arm A, one entry per repetition.

§b_ns: Vec<f64>

Nanoseconds per iteration for arm B, one entry per repetition.

§ratios: Vec<f64>

b_ns[i] / a_ns[i], one entry per repetition. Above 1 ⇒ A faster.

§a_went_first: Vec<bool>

true when arm A was timed first in that repetition.

Implementations§

Source§

impl PairedTiming

Source

pub fn median_ratio(&self) -> f64

Median of the paired ratios — the headline estimate.

The median rather than the mean because a single descheduled repetition produces an arbitrarily large outlier in one direction only, and rather than a minimum because a minimum is the statistic that preserves a systematic offset (see the module docs).

Source

pub fn wins_fraction(&self) -> f64

Fraction of repetitions in which A was faster than B.

This is the gate’s honesty check. A median ratio of 1.06 with a wins fraction of 1.0 is a real effect; the same 1.06 with 0.55 means the repetitions disagree with each other and the point estimate is riding on a few draws.

Source

pub fn ratio_resolution(&self) -> f64

Half the central 90% span of the paired ratios, as a fraction of the median — the gate’s own resolution.

A claimed margin smaller than this is not measurable by this harness at this repetition count, and asserting it is asserting noise. Report it beside the margin so the comparison is visible.

Source

pub fn first_position_bias(&self) -> f64

Median ratio among repetitions where A ran first, minus the median among those where B ran first.

This is the diagnostic the old harnesses could not produce, because they never varied the order. A value near zero says position does not matter on this host; a large value says the measurement is dominated by whichever arm goes first, and no ordering of a non-randomised harness would have been trustworthy. Returns NaN if either group is empty.

Source

pub fn summary(&self, a_label: &str, b_label: &str) -> String

One line carrying everything needed to audit the verdict, including the numbers that would reveal the verdict as unsupported.

Examples found in repository?
examples/paired_timing_report.rs (line 111)
91fn main() {
92    let input: [f64; 17] = std::array::from_fn(|index| 0.35 + 0.07 * (index as f64 + 1.0).sin());
93    for (compiled, canonical) in compiled_bundle4(input).iter().zip(canonical_bundle4(input).iter()) {
94        assert!((compiled - canonical).abs() <= 1e-12 * canonical.abs().max(1.0));
95    }
96    let timing = paired_interleaved(
97        15,
98        2_000,
99        0x9320_AB,
100        batched(64, |nudge| {
101            let mut x = input;
102            x[4] += nudge;
103            compiled_bundle4(x).iter().sum()
104        }),
105        batched(64, |nudge| {
106            let mut x = input;
107            x[4] += nudge;
108            canonical_bundle4(x).iter().sum()
109        }),
110    );
111    println!("{}", timing.summary("compiled_bundle4", "nine_top_channels"));
112    // The two contracts a gate can carry, printed the way a gate prints them.
113    let mut gate = SpeedGate::open("PAIRED-TIMING-REPORT");
114    gate.faster("order=4 bundle", &timing, "compiled_bundle4", "nine_top_channels");
115    gate.not_slower("order=4 bundle", &timing, "compiled_bundle4", "nine_top_channels");
116    gate.finish();
117}

Trait Implementations§

Source§

impl Clone for PairedTiming

Source§

fn clone(&self) -> PairedTiming

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PairedTiming

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.