fine_grained/
lib.rs

1// Copyright 2017 Bastian Meyer
2//
3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or http://apache.org/licenses/LICENSE-2.0> or the
4// MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option. This file may not be copied,
5// modified, or distributed except according to those terms.
6
7//! A stopwatch with lap functionality and nanosecond resolution to time things.
8//!
9//! Measured times are stored and returned in nanoseconds.
10//!
11//! # Examples
12//!
13//! Get a single measurement:
14//!
15//! ```
16//! extern crate fine_grained;
17//!
18//! use fine_grained::Stopwatch;
19//!
20//! fn main() {
21//!     // Get a new stopwatch and start it.
22//!     let mut stopwatch = Stopwatch::start_new();
23//!
24//!     // Do something long and time it.
25//!     // do_something_long();
26//!     println!("Duration: {duration}ns", duration = stopwatch);
27//!     stopwatch.stop();
28//! }
29//! ```
30//!
31//! Get measurements for repetitive tasks and a total time:
32//!
33//! ```
34//! extern crate fine_grained;
35//!
36//! use fine_grained::Stopwatch;
37//!
38//! fn main() {
39//!     // Get a new stopwatch and start it.
40//!     let mut stopwatch = Stopwatch::start_new();
41//!
42//!     // Do something repetitive you want to time.
43//!     for _ in 0..10 {
44//!         // do_something_repetitive();
45//!         stopwatch.lap();
46//!     }
47//!     stopwatch.stop();
48//!
49//!     // Print the timing results.
50//!     for (i, &lap) in stopwatch.laps().into_iter().enumerate() {
51//!         println!("Round {i}: {duration}ns", i = i, duration = lap);
52//!     }
53//!     println!("Total time: {duration}ns", duration = stopwatch);
54//! }
55//! ```
56//!
57//! Get measurements for multiple independent tasks and a total time:
58//!
59//! ```
60//! extern crate fine_grained;
61//!
62//! use fine_grained::Stopwatch;
63//!
64//! fn main() {
65//!     // Get a new stopwatch and start it.
66//!     let mut stopwatch = Stopwatch::start_new();
67//!
68//!     // Do foo.
69//!     // do_foo();
70//!     let time_to_do_foo: u64 = stopwatch.lap();
71//!
72//!     // Do bar.
73//!     // do_bar();
74//!     let time_to_do_bar: u64 = stopwatch.lap();
75//!
76//!     // Do foobar.
77//!     // do_foobar();
78//!     let time_to_do_foobar: u64 = stopwatch.lap();
79//!
80//!     stopwatch.stop();
81//!     println!("Time to do foo: {duration}ns", duration = time_to_do_foo);
82//!     println!("Time to do bar: {duration}ns", duration = time_to_do_bar);
83//!     println!("Time to do foobar: {duration}ns", duration = time_to_do_foobar);
84//!     println!("Total time: {duration}ns", duration = stopwatch);
85//! }
86//! ```
87//!
88//! # Inspiration
89//!
90//! Inspired by Chucky Ellison's stopwatch (https://github.com/ellisonch/rust-stopwatch).
91
92#![warn(missing_docs,
93        missing_debug_implementations, missing_copy_implementations,
94        trivial_casts, trivial_numeric_casts,
95        unused_extern_crates, unused_import_braces, unused_qualifications, unused_results)]
96#![cfg_attr(feature = "cargo-clippy", warn(empty_enum, enum_glob_use, if_not_else, items_after_statements,
97                                           missing_docs_in_private_items, nonminimal_bool, option_unwrap_used,
98                                           pub_enum_variant_names, print_stdout, result_unwrap_used, similar_names,
99                                           single_match_else, stutter, used_underscore_binding, use_debug,
100                                           wrong_self_convention, wrong_pub_self_convention))]
101
102extern crate time;
103
104pub use self::stopwatch::Stopwatch;
105
106mod stopwatch;