Struct RollingRateCounter

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

A rolling update counter. It records as many updates as the given sample rate and re-calculates the average update time on each call to update.

Generally, this is to be preferred over the discrete version. However, for very high values of sample, this can be quite inefficient, especially if the rate value isn’t needed during each cycle.

§Usage

Call .update() every time your system starts a new update/cycle; for instance, an FPS counter would call this at the beginning of every frame. The sample rate (set with set_sample_rate() and in the first argument to new()) governs how many .update() calls are required before a meaningful result is produced.

You can also use .update_immut() for this to avoid a mutable binding.

Implementations§

Source§

impl RollingRateCounter

Source

pub fn new(samples: u64) -> Self

Create a new RollingRateCounter which calculates the update rate every update, averaging over a window of update_rate cycles.

§Panics

This function will panic if given a value of samples equal to 0.

Trait Implementations§

Source§

impl Clone for RollingRateCounter

Source§

fn clone(&self) -> RollingRateCounter

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RollingRateCounter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for RollingRateCounter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl RateCounter for RollingRateCounter

Source§

fn samples(&self) -> u64

Return the current number of samples the UpdateRateCounter is measuring.
Source§

fn set_samples(&mut self, samples: u64)

Set the number of updates which the UpdateRateCounter considers. Read more
Source§

fn update(&mut self)

Updates the struct in place, but requires a mutable binding. Call either this OR update_immut() at the beginning of each cycle of the periodic activity being measured.
Source§

fn rate(&self) -> f64

Return the last calculated rate of operation, in Hertz (updates per second).

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.