Struct solana_measure::measure::Measure
source · [−]pub struct Measure { /* private fields */ }
Implementations
sourceimpl 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");
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Measure
impl Send for Measure
impl Sync for Measure
impl Unpin for Measure
impl UnwindSafe for Measure
Blanket Implementations
impl<T> AbiExample for T
impl<T> AbiExample for T
default fn example() -> T
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more