Macro gbench::instantiate[][src]

macro_rules! instantiate {
    ($name : ident | $($writer : expr), *) => { ... };
    ($($writer : expr), *) => { ... };
}
Expand description

Instantiates the global variables for benchmark logging

This macro should be used at the top of any program using this crate.

Implementation

This macro expands into a declaration of Instantiator which instantiates global variables on creation and deinstantiates them on drop.

instantiate!(ChromeTracing("target/bench"));
// expands into this
let __gbench_instantiator__ = Instantiator::new(vec![Box::new(ChromeTracing("target/bench"))]);

If you need to deinstantiate global variables before variable goes out of scope you can specify the variable name and then call end on it when you need the deinstantiation.

instantiate!(ginst | ChromeTracing("target/bench"));
// expands into this
let ginst = Instantiator::new(vec![Box::new(ChromeTracing("target/bench"))]);

Examples

use gbench::{instantiate, scope, ChromeTracing};

fn main() {
    instantiate!(ChromeTracing("target/bench"));
    {
        scope!(sc | "Scope");

        for _ in 0..1_000_000 {
            let _a = 1 + 1;
        }
    }
}

or using end

use gbench::{instantiate, scope, ChromeTracing};

fn main() {
    instantiate!(ginst | ChromeTracing("target/bench"));
    {
        scope!(sc | "Scope");

        for _ in 0..1_000_000 {
            let _a = 1 + 1;
        }
    }
    ginst.end();
}