#timer #time #duration

eggtimer

Timer types for measuring time in a program in different ways

3 unstable releases

0.2.0 Nov 13, 2018
0.1.1 Nov 13, 2018
0.1.0 Nov 13, 2018

#82 in Date and time

Download history 87/week @ 2018-11-19 10/week @ 2018-11-26 28/week @ 2018-12-03 18/week @ 2018-12-10

5 downloads per month

MIT license

16KB
326 lines

Description

This crate provides Rust timer types for measuring time in a program in different ways.

  • Timer is a timer that counts up and knows how much time has passed since it was started.
  • EggTimer is a timer that counts down from its set Duration and knows how much time it has left.
  • Stopwatch is a timer that counts up and can be paused and resumed.

In addition to the timer types, a collection type, TimedList, is provided, which associates each element with a Duration and only retains elements whose Duration has not elapsed.

Usage

To use this crate, add this to your Cargo.toml:

[dependencies]
eggtimer = "0.3.1"

Example

use eggtimer::Timer;

fn computation() {
    // Do some computation that takes some time.
}

fn main() {
    // Start the timer
    let timer = Timer::start();

    // Do a computation
    computation();

    // Check how long it took
    let elapsed = timer.elapsed();
    println!("The computation took {} seconds.", elapsed);
}

No runtime deps