Struct solana_measure::measure::Measure
source · pub struct Measure { /* private fields */ }
Implementations§
source§impl Measure
impl Measure
pub fn start(name: &'static str) -> Self
pub fn stop(&mut self)
pub fn as_ns(&self) -> u64
pub fn as_us(&self) -> u64
pub fn as_ms(&self) -> u64
pub fn as_s(&self) -> f32
sourcepub fn this<T, R, F: FnOnce(T) -> R>(
func: F,
args: T,
name: &'static str
) -> (R, Self)
pub fn this<T, R, F: FnOnce(T) -> R>(
func: F,
args: T,
name: &'static str
) -> (R, Self)
Measure this function
Use Measure::this()
when you have a function that you want to measure. this()
will
start a new Measure
, call your function, stop the measure, then return the Measure
object along with your function’s return value.
If your function takes more than one parameter, you will need to wrap your function in a closure, and wrap the arguments in a tuple. The same thing applies to methods. See the tests for more details.
Examples
// Call a function with a single argument
let (result, measure) = Measure::this(my_function, 42, "my_func");
// Call a function with multiple arguments
let (result, measure) = Measure::this(|(arg1, arg2)| std::cmp::min(arg1, arg2), (42, 123), "minimum");
// Call a method
let foo = Foo { x: 42 };
let (result, measure) = Measure::this(|(this, args)| Foo::bar(&this, args), (&foo, baz), "Foo::bar");