#timer #timing #perf #time #voxell

voxell_timer

Perf timers for Rust

4 releases

new 0.2.3 Nov 16, 2024
0.2.2 Nov 16, 2024
0.2.0 Nov 16, 2024
0.1.0 Oct 18, 2024

#14 in #perf

Download history 163/week @ 2024-10-14 13/week @ 2024-10-21 123/week @ 2024-11-11

148 downloads per month

Custom license

14KB
232 lines

Voxell's Timers

let data = time_eprintln!{"Data generation", generate_data() };
// -> Data generation: 309ms

This library provides a simple way to time code execution. Simply use the provided macros/functions to time your code to get a Duration and the result of the block/closure.

Example 1

let (result, time) = time! {
    for _ in 0..1_000_000 {
        let _ = std::hint::black_box(3);
    }
    10
};
eprintln!("Took {}ms", time.as_millis());
assert_eq!(result, 10);

Example 2

let haystack = vec![1, 2, 3, 4, 5, 6];
let result = time_println!  {
    "Finding needle in haystack",
    let needle = 4;
    haystack.iter().find(|a| **a == needle)
};

assert_eq!(result, Some(&4));

Example 3

let haystack = vec![1, 2, 3, 4, 5, 6];
let result = time_fn_println("Finding needle in haystack", || {
   let needle = 4;
   haystack.iter().find(|a| **a == needle)
});
assert_eq!(result, Some(&4));

No runtime deps