solana_measure

Macro measure_time

Source
macro_rules! measure_time {
    ($val:expr, $name:tt $(,)?) => { ... };
    ($val:expr) => { ... };
}
Expand description

Measure this expression

Use measure_time!() when you have an expression that you want to measure. measure_time!() will start a new Measure, evaluate your expression, stop the Measure, and then return the Measure object along with your expression’s return value.

Use measure_us!() when you want to measure an expression in microseconds.

Use meas_dur!() when you want to measure an expression and get the Duration.

§Examples

// Measure functions
let (result, measure) = measure_time!(foo(), "foo takes no parameters");
let (result, measure) = measure_time!(bar(42), "bar takes one parameter");
let (result, measure) = measure_time!(add(1, 2), "add takes two parameters and returns a value");
let (result, measure_us) = measure_us!(add(1, 2));
let (result, duration) = meas_dur!(add(1, 2));
// Measure methods
let foo = Foo { f: 42 };
let (result, measure) = measure_time!(foo.frobnicate(2), "measure methods");
let (result, measure_us) = measure_us!(foo.frobnicate(2));
let (result, duration) = meas_dur!(foo.frobnicate(2));
// Measure expression blocks
let (result, measure) = measure_time!(
    {
        let x = complex_calculation();
        let y = complex_transform(x);
        record_result(y);
        y
    },
    "measure a block of many operations",
);
// The `name` parameter is optional
let (result, measure) = measure_time!(meow());
let (result, measure_us) = measure_us!(meow());