Skip to main content

timed/
lib.rs

1//! # Timed
2//!
3//! Macros for measuring function execution.
4//! ```
5//! #[timed::timed]
6//! fn add(x: i32, y: i32) -> i32 {
7//!     x + y
8//! }
9//! ```
10//! It will output:
11//! ```
12//! // function=add duration=112ns
13//! ```
14//! Times the execution of the function
15//!
16//! # Examples
17//!
18//! ```
19//! use timed::timed;
20//!
21//! #[timed]
22//! fn add(x: i32, y: i32) -> i32 {
23//!     x + y
24//! }
25//!
26//! #[timed(duration(printer = "println!"))]
27//! async fn google()  {
28//!     // reqwest::get("https://google.com").await;
29//! }
30//! ```
31//!
32//! ```ignore
33//! #[timed(printer = "info!")]
34//! fn add_info(x: i32, y: i32) -> i32 {
35//!     x + y
36//! }
37//! ```
38//!
39//! ```ignore
40//! #[tokio::main]
41//! #[timed]
42//! async fn main() {
43//!     reqwest::get("https://google.com").await;
44//! }
45//!
46//! ```
47
48use std::collections::HashMap;
49use std::sync::Mutex;
50
51#[macro_use]
52extern crate lazy_static;
53#[macro_use]
54extern crate prettytable;
55
56mod chrome_trace;
57mod hop;
58mod statistics;
59mod trace;
60
61// export Trace
62pub use hop::{Hop, Phase};
63pub use trace::Trace;
64
65// Re-exporting the timed proc macro
66pub use timed_proc_macros::timed;
67
68// Keeping track of traces
69lazy_static! {
70    static ref TRACES: Mutex<HashMap<String, Vec<hop::Hop>>> = Mutex::new(HashMap::new());
71}