Timer

Struct Timer 

Source
pub struct Timer { /* private fields */ }
Expand description

A struct for timing and logging time durations.

Timer uses a HashMap to store multiple named timers, each associated with a label.

Implementations§

Source§

impl Timer

Source

pub fn new() -> Self

Creates a new Timer instance.

§Returns

Returns a new Timer instance with an empty timer HashMap.

Source

pub fn time(&mut self, label: &str)

Starts a new timer.

§Arguments
  • label - The label for the timer.
Source

pub fn time_log(&self, label: &str, silent: bool) -> f64

Logs and prints the current time of a timer without stopping it.

§Arguments
  • label - The label of the timer.
  • silent - Whether to suppress printing the message.
§Returns

Returns the number of milliseconds the timer has been running, or 0.0 if the timer doesn’t exist.

Source

pub fn time_end(&mut self, label: &str, silent: bool) -> f64

Ends a timer and prints its runtime.

§Arguments
  • label - The label of the timer.
  • silent - Whether to suppress printing the message.
§Returns

Returns the number of milliseconds the timer has been running, or 0.0 if the timer doesn’t exist.

Source

pub fn single_instance() -> &'static mut Timer

Returns a global singleton instance of Timer

This method implements the singleton pattern to ensure only one Timer instance exists throughout the program. It’s thread-safe and lazily initialized.

§Returns

A static mutable reference to the global Timer instance

§Safety

This function uses an unsafe block because it manipulates static mutable variables. However, thread safety is guaranteed by using Once to ensure initialization happens only once.

Trait Implementations§

Source§

impl Default for Timer

Implements the Default trait for Timer.

Source§

fn default() -> Self

Creates a default Timer instance.

§Returns

Returns a new Timer instance.

Auto Trait Implementations§

§

impl Freeze for Timer

§

impl RefUnwindSafe for Timer

§

impl Send for Timer

§

impl Sync for Timer

§

impl Unpin for Timer

§

impl UnwindSafe for Timer

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.