Skip to content

Commit

Permalink
Add iter_n
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Jan 19, 2018
1 parent 10dde7e commit b37b88f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions text/0000-benchmarking.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
```

Expand Down Expand Up @@ -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());
}
```

Expand Down

0 comments on commit b37b88f

Please sign in to comment.