1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 2017 Bastian Meyer
//
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or http://apache.org/licenses/LICENSE-2.0> or the
// MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option. This file may not be copied,
// modified, or distributed except according to those terms.
//! A stopwatch with lap functionality and nanosecond resolution to time things.
//!
//! Measured times are stored and returned in nanoseconds.
//!
//! # 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 independent 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).
extern crate time;
pub use Stopwatch;