[−][src]Struct update_rate::DiscreteRateCounter
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]
fn clone(&self) -> DiscreteRateCounter
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for DiscreteRateCounter
[src]
impl Debug for DiscreteRateCounter
[src]
impl Display for DiscreteRateCounter
[src]
impl RateCounter for DiscreteRateCounter
[src]
fn samples(&self) -> u64
[src]
fn set_samples(&mut self, samples: u64)
[src]
fn update(&mut self)
[src]
fn rate(&self) -> f64
[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
impl RefUnwindSafe for DiscreteRateCounter
impl Send for DiscreteRateCounter
impl Sync for DiscreteRateCounter
impl Unpin for DiscreteRateCounter
impl UnwindSafe for DiscreteRateCounter
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,