#stopwatch #timer #timekeeper

simple-stopwatch

Minimal stopwatch for rust, returns float values

5 releases

Uses old Rust 2015

0.1.4 Jan 21, 2018
0.1.3 Jan 21, 2018
0.1.2 Jan 21, 2018
0.1.1 Jan 21, 2018
0.1.0 Jan 21, 2018

#23 in #stopwatch

Download history 44/week @ 2023-12-04 23/week @ 2023-12-11 46/week @ 2023-12-18 46/week @ 2023-12-25 31/week @ 2024-01-01 58/week @ 2024-01-08 82/week @ 2024-01-15 29/week @ 2024-01-22 46/week @ 2024-01-29 14/week @ 2024-02-05 44/week @ 2024-02-12 55/week @ 2024-02-19 48/week @ 2024-02-26 53/week @ 2024-03-04 62/week @ 2024-03-11 73/week @ 2024-03-18

238 downloads per month

MIT license

6KB

rust-simple-stopwatch

Build Status

What is it?

A minimal no-thrills stopwatch. Returns time values as floats. Uses time::precise_time_ns under the hood.

Setup

Add the dependency simple-stopwatch to your Cargo.toml file, for example:

[dependencies]
simple-stopwatch="0.1.4"

Then import the stopwatch anywhere you would like to use it:

extern crate simple_stopwatch;
use simple_stopwatch::Stopwatch;

Example Use

There is minimal state in simple-stopwatch. Upon creation it grabs a timestamp, from which point its member functions will return elapsed time.

fn my_function() {
  let sw = Stopwatch::start_new();
  
  do_some_heavy_work();
  
  let elapsed_ms = sw.ms();
  println!("Time taken: {}ms", elapsed_ms);
}

The restart method updates the stored timestamp to the current time.

The code make use of a small amount of code from the time crate, which uses a system call to obtain a high precision time stamp. The overhead of this call appears to be very small from my experiments so far.

Inspiration / Other Projects

Dependencies

~0.6–1MB
~14K SLoC