3 releases

Uses old Rust 2015

0.1.2 Jun 27, 2015
0.1.1 Jun 27, 2015
0.1.0 Jun 27, 2015

#347 in Profiling

Download history 239/week @ 2023-11-16 227/week @ 2023-11-23 199/week @ 2023-11-30 168/week @ 2023-12-07 171/week @ 2023-12-14 137/week @ 2023-12-21 69/week @ 2023-12-28 159/week @ 2024-01-04 203/week @ 2024-01-11 121/week @ 2024-01-18 91/week @ 2024-01-25 81/week @ 2024-02-01 143/week @ 2024-02-08 239/week @ 2024-02-15 143/week @ 2024-02-22 148/week @ 2024-02-29

685 downloads per month
Used in 17 crates (14 directly)

MIT license

5KB
50 lines

Timeit for Rust

This crate provides macros that make it easy to benchmark blocks of code. It is inspired and named after timeit from Python.

Examples

#[macro_use]
extern crate timeit;

fn main() {
    timeit!({
        let mut x: Vec<u64> = Vec::new();
        for i in 0..1000 {
            x.push(i);
        }
    });
}

This will output something like:

10000 loops: 2.4843 µs

It will determine the number of loops automatically. To run a specified number of loops and save the elapsed time to a variable, use the timeit_loops! macro:

let sec = timeit_loops!(100, {
    let mut x: Vec<u64> = Vec::new();
    for i in 0..1000 {
        x.push(i);
    }
});

lib.rs:

This crate provides macros that make it easy to benchmark blocks of code. It is inspired and named after timeit from Python.

Example:

#[macro_use]
extern crate timeit;

fn main() {
    timeit!({
        let mut x: Vec<u64> = Vec::new();
        for i in 0..1000 {
            x.push(i);
        }
    });
}

This will output something like:

10000 loops: 2.4843 µs

It will determine the number of loops automatically. To run a specified number of loops and save the elapsed time to a variable, use the timeit_loops! macro:

let sec = timeit_loops!(100, {
    let mut x: Vec<u64> = Vec::new();
    for i in 0..1000 {
        x.push(i);
    }
});

Dependencies

~0.6–1MB
~14K SLoC