Crate timeit [−] [src]
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); } });
Macros
timeit |
Runs a block several times and outputs the average time per loop. The number of loops is determined automatically. |
timeit_loops |
Runs a block a specified number of times and returns the average time of execution. |
Functions
get_time |
A shortcut to time's |