Skip to main content

timing_test_checked

Macro timing_test_checked 

Source
timing_test_checked!() { /* proc-macro */ }
Expand description

Create a timing test that returns Outcome for explicit handling.

This macro is identical to timing_test! - both return Outcome. It is kept for backwards compatibility.

§Returns

Returns Outcome which is one of Pass, Fail, Inconclusive, or Unmeasurable.

§Example

use tacet::{timing_test_checked, Outcome};

fn main() {
    let outcome = timing_test_checked! {
        baseline: || [0u8; 32],
        sample: || rand::random::<[u8; 32]>(),
        measure: |input| {
            let _ = std::hint::black_box(&input);
        },
    };

    match outcome {
        Outcome::Pass { leak_probability, .. } |
        Outcome::Fail { leak_probability, .. } |
        Outcome::Inconclusive { leak_probability, .. } => {
            println!("Leak probability: {:.1}%", leak_probability * 100.0);
        }
        Outcome::Unmeasurable { recommendation, .. } => {
            println!("Operation too fast: {}", recommendation);
        }
    }
}