2 unstable releases

0.2.0 Nov 19, 2022
0.1.0 Nov 16, 2022

#330 in Profiling

Download history 65/week @ 2024-10-09 51/week @ 2024-10-16 79/week @ 2024-10-23 29/week @ 2024-10-30 36/week @ 2024-11-06 18/week @ 2024-11-13 27/week @ 2024-11-20 50/week @ 2024-11-27 38/week @ 2024-12-04 62/week @ 2024-12-11 123/week @ 2024-12-18 10/week @ 2024-12-25 8/week @ 2025-01-01 136/week @ 2025-01-08 186/week @ 2025-01-15 82/week @ 2025-01-22

412 downloads per month

MIT/Apache

17KB

Crates.io MIT/Apache 2.0

might_sleep

Rust library for limiting the cpu usage by trying to target a specific frame rate. The library will internally estimate the time we need to sleep to reach the target fps, taking the programs execution time into account.

example code:

mod usage {
    use std::time::Duration;

    pub const LOW: Duration = Duration::from_millis(100);
    pub const NORMAL: Duration = Duration::from_millis(50);
}

fn main() {
    let mut cpu_limiter = CpuLimiter::new(usage::LOW);

    cpu_limiter.duration = usage::NORMAL; // usage is now normal (50ms delay)
    loop {
        println!("should be called every 50 ms");
        cpu_limiter.might_sleep();
    }
}

License

might_sleep is free and open source! All code in this repository is dual-licensed under either:

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps