fine_grained 0.1.2

A stopwatch with lap functionality and nanosecond resolution to time things.
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented1 out of 1 items with examples
  • Size
  • Source code size: 34.12 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.81 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • BMeu/Fine-Grained
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • BMeu

Fine-Grained

Build Status codecov crates.io Documentation

A Rust stopwatch with lap functionality and nanosecond resolution.

Examples

Get a single measurement:

extern crate fine_grained;

use fine_grained::Stopwatch;

fn main() {
    // Get a new stopwatch and start it.
    let mut stopwatch = Stopwatch::start_new();

    // Do something long and time it.
    // do_something_long();
    println!("Duration: {duration}ns", duration = stopwatch);
    stopwatch.stop();
}

Get measurements for repetitive tasks and a total time:

extern crate fine_grained;

use fine_grained::Stopwatch;

fn main() {
    // Get a new stopwatch and start it.
    let mut stopwatch = Stopwatch::start_new();

    // Do something repetitive you want to time.
    for _ in 0..10 {
        // do_something_repetitive();
        stopwatch.lap();
    }
    stopwatch.stop();

    // Print the timing results.
    for (i, &lap) in stopwatch.laps().into_iter().enumerate() {
        println!("Round {i}: {duration}ns", i = i, duration = lap);
    }
    println!("Total time: {duration}ns", duration = stopwatch);
}

Get measurements for multiple indepedent tasks and a total time:

extern crate fine_grained;

use fine_grained::Stopwatch;

fn main() {
    // Get a new stopwatch and start it.
    let mut stopwatch = Stopwatch::start_new();

    // Do foo.
    // do_foo();
    let time_to_do_foo: u64 = stopwatch.lap();

    // Do bar.
    // do_bar();
    let time_to_do_bar: u64 = stopwatch.lap();

    // Do foobar.
    // do_foobar();
    let time_to_do_foobar: u64 = stopwatch.lap();

    stopwatch.stop();
    println!("Time to do foo: {duration}ns", duration = time_to_do_foo);
    println!("Time to do bar: {duration}ns", duration = time_to_do_bar);
    println!("Time to do foobar: {duration}ns", duration = time_to_do_foobar);
    println!("Total time: {duration}ns", duration = stopwatch);
}

Inspiration

Inspired by Chucky Ellison's stopwatch (https://github.com/ellisonch/rust-stopwatch).

License

CRGP is licensed under either of

at your option.

Contribution

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.