Crate update_rate [] [src]

This crate provides a utility for counting updates, for instance frame rates.

The struct UpdateRateCounter has a method, .update(), which is meant to be called every time your system updates (e.g. every frame, every physics update, etc).

This can also be done immutably using shadowing and .update_immut().

Examples

The one important thing to remember is to call your Counter's update() (or update_immut()) at the beginning of your cycles.

use update_rate::UpdateRateCounter;

// Create a new UpdateRateCounter with a sample rate of 10 updates
let mut c = UpdateRateCounter::new(10);

for _ in 1..11 {
    c.update();
    // Rate should be 100 Hz with 10 ms/update
    std::thread::sleep(std::time::Duration::from_millis(10));
}

let difference = 100.0 - c.rate();
println!("Rate was {}", c.rate());
assert!(difference < 10.0, "Counter rate should be closer to actual rate.");

Structs

UpdateRateCounter

A generic non-rolling update counter, suitable for rapidly-changing rate counting, such as FPS counters in games.