From b37b88f794dcf2e9a17a78f21f77dce6b957044c Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 19 Jan 2018 12:26:11 +0530 Subject: [PATCH] Add iter_n --- text/0000-benchmarking.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/text/0000-benchmarking.md b/text/0000-benchmarking.md index 0b008467004..2714bad3d78 100644 --- a/text/0000-benchmarking.md +++ b/text/0000-benchmarking.md @@ -60,7 +60,7 @@ fn pow(x: u32, y: u32) -> u32 { #[bench] fn my_benchmark(bench: Bencher) -> BenchResult { - bench.iter(|| pow(4, 30)); + bench.iter(|| pow(4, 30)) } ``` @@ -107,7 +107,16 @@ fn my_benchmark(bench: Bencher) -> BenchResult { bench.iter(|| { black_box(pow(y, x)); pow(x, y) - }); + }) +} +``` + +In case you want the benchmark to run for a predetermined number of times, use `iter_n`: + +```rust +#[bench] +fn my_benchmark(bench: Bencher) -> BenchResult { + bench.iter_n(1000, || do_some_stuff()); } ```