#benchmarking

ttimer

A tiny crate used for timing individual functions

4 releases

0.1.3 Dec 15, 2023
0.1.2 Dec 13, 2023
0.1.1 Dec 13, 2023
0.1.0 Dec 13, 2023

#37 in #benchmarking

33 downloads per month

MIT license

6KB
60 lines

ttimer

A simple and tiny timing crate.

Example Usage

// time a function's execution
let result = timer!(some_function);

println!("Took {} ns", result.time.as_nanos());

// time execution and use output
fn some_function(a: i32, b: &str) -> Option<usize> {
    /* code */
}

let result = timer!(some_function, 12, "Some input string");

if let Some(value) = result.result {
    println!("Took {} ns to find {}", result.time.as_nanos(), value);
} else {
    println!("Took {} ns", result.time.as_nanos());
}

lib.rs:

A tiny crate for timing / benchmarking your Rust functions

Example:

use ttimer::*;

fn fib(n: u32) -> u32 {
    if n < 2 {
        n
    } else {
        fib(n - 1) + fib(n - 2)
    }
}

// Time the function `fib` with the input `40`
let result = timer!(fib, 40);

assert_eq!(result.name, "fib");
assert_eq!(result.result, 102334155);

println!("{} took {} ms to complete", result.name, result.time.as_millis());

// You can also quickly print out the runtime information.
// This code will print "fib done in {some_time} ms"
timer!(fib, 25).view();

No runtime deps