Microbenchmarks macro
Measures the average time for a given number of iterations. Easy to use, zero deps.
Cargo.toml
[]
= "0.1"
main.rs
extern crate mbench;
Output
The default is 10 iterations, but you can set an arbitrary number microbench!(4, {/* code */});.
microbench!;
In addition, there is a simplified syntax for setting the number of iterations (1,5,10,50,100,500,1000):
microbench1!;
microbench5!;
microbench10!;
microbench50!;
microbench100!;
microbench500!;
microbench1000!;
With macro fixedbench!([0..=2], 10, {/* code */}); you can set
the range in milliseconds (and optionally 10 iterations in this example).
If the code runs longer or faster than the interval specified,
then there will be a panic.
This can be used in tests. The test fails if the code becomes slower after the change. The default is 1 iteration.
extern crate mbench;
Keep in mind that the running time of the code may vary on different machines. After completing work on a piece of code, such a test should be removed or commented out.