timeit 0.1.2

Timing macros for Rust modelled after Python's timeit
Documentation
  • Coverage
  • 100%
    4 out of 4 items documented1 out of 2 items with examples
  • Size
  • Source code size: 6.33 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.31 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • gustavla/timeit
    16 5 2
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • gustavla

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);
    }
});