[][src]Struct update_rate::DiscreteRateCounter

pub struct DiscreteRateCounter { /* fields omitted */ }

A very basic non-rolling update counter. It counts n updates, calculates, and then resets (where n is the sample rate), which means that it takes at least n updates to react to a change in rate appropriately.

Generally, the RollingRateCounter is a better instrument, but it has to recalculate its measured rate every time it is queried whereas the DiscreteRateCounter only recalculates every n cycles.

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. Since DiscreteRateCounter is small and easily copyable, this is negligibly less efficient.

Implementations

impl DiscreteRateCounter[src]

pub fn new(samples: u64) -> Self[src]

Create a new DiscreteRateCounter which calculates the update rate every samples cycles. Until that many cycles occur, rate() will return a useless value, typically 0.0.

If this isn't acceptable, one strategy is to start the samples value at 0 and keep ramping it up until it reaches your target samples value; however, the data near the beginning will not be useful.

pub fn rate_age_cycles(&self) -> u64[src]

Return the number of cycles since the rate was last recalculated.

pub fn rate_age_duration(&self) -> Duration[src]

Return the amount of time since the rate was last recalculated. This requires examining the system clock and is thus relatively expensive.

Trait Implementations

impl Clone for DiscreteRateCounter[src]

impl Copy for DiscreteRateCounter[src]

impl Debug for DiscreteRateCounter[src]

impl Display for DiscreteRateCounter[src]

impl RateCounter for DiscreteRateCounter[src]

impl RateCounterImmut for DiscreteRateCounter[src]

fn update_immut(self) -> Self[src]

Consumes the struct and returns an updated version. Call this at the beginning of each cycle of the periodic activity being measured.

Examples

use update_rate::DiscreteRateCounter;
use update_rate::{RateCounter, RateCounterImmut};
let c = DiscreteRateCounter::new(5);
for i in 1..101 {
    let c = c.update_immut();
    if i % 10 == 0 {println!("Rate: {}", c.rate())}
    // Do work here
}

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.