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.

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");
// Measure methods
let foo = Foo { f: 42 };
let (result, measure) = measure!(foo.frobnicate(2), "measure methods");
// 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());