solana_measure

Macro measure

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

Measure this expression

Use measure!() when you have an expression that you want to measure. measure!() 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.

§Examples

// Measure functions
let (result, measure) = measure!(foo(), "foo takes no parameters");
let (result, measure) = measure!(bar(42), "bar takes one parameter");
let (result, measure) = measure!(add(1, 2), "add takes two parameters and returns a value");
let (result, measure_us) = measure_us!(add(1, 2));
// Measure methods
let foo = Foo { f: 42 };
let (result, measure) = measure!(foo.frobnicate(2), "measure methods");
let (result, measure_us) = measure_us!(foo.frobnicate(2));
// Measure expression blocks
let (result, measure) = measure!(
    {
        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!(meow());
let (result, measure_us) = measure_us!(meow());