#stopwatch #timing #split #clear #original #rewrite #time

stopwatch2

A stopwatch library for timing things. A rewrite and simplification of the original stopwatch crate.

1 stable release

2.0.0 Apr 30, 2021

#344 in Date and time

Download history 370/week @ 2024-11-15 422/week @ 2024-11-22 367/week @ 2024-11-29 469/week @ 2024-12-06 476/week @ 2024-12-13 272/week @ 2024-12-20 251/week @ 2024-12-27 384/week @ 2025-01-03 638/week @ 2025-01-10 454/week @ 2025-01-17 296/week @ 2025-01-24 400/week @ 2025-01-31 322/week @ 2025-02-07 255/week @ 2025-02-14 455/week @ 2025-02-21 438/week @ 2025-02-28

1,541 downloads per month
Used in 7 crates (6 directly)

MIT license

10KB
159 lines

Stopwatch2

Stopwatch V2

Support an Open Source Developer! ♥️
Become a patron

Read the documentation.

This crate is a simplified version of the work of ellisonch.

Features

  • Adds a simple stopwatch.
  • Can use multiple splits, even with pauses between them!
  • Simple to use with clear documentation.

Usage

Add the following to you Cargo.toml file:

stopwatch2 = "*"

Use the stopwatch like so:

use stopwatch2::*;

fn main() {
    let mut s = Stopwatch::default();
    s.start(); // Starts the stopwatch.
    s.start(); // Creates a new time span, which are commonly called "splits".
    s.stop(); // Stops the stopwatch.
    println!("{}", s); // Prints the total time.
    println!("{:?}", s); // Prints the different time spans as debug information.
    let total_time = s.elapsed(); // returns the total time as a Duration.
    for span in &s.spans {
        // Prints all contained time spans.
        println!("{:?} -> {:?}", span.start, span.stop);
    }
    s.spans.clear(); // Reset the stopwatch.
    println!("{}", s); // Prints the total time.
    println!("{:?}", s); // Prints the different time spans as debug information.
}

Maintainer Information

  • Maintainer: Jojolepro
  • Contact: jojolepro [at] jojolepro [dot] com
  • Website: jojolepro.com
  • Patreon: patreon

No runtime deps