From ea4543f63a8db4504aca146ccdcc518ecee3d9be 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 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/text/0000-benchmarking.md b/text/0000-benchmarking.md index 0b008467004..7a5d426a641 100644 --- a/text/0000-benchmarking.md +++ b/text/0000-benchmarking.md @@ -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()); } ```