aboutsummaryrefslogtreecommitdiff
path: root/src/tests/aoc-2022-08/benches/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/aoc-2022-08/benches/main.rs')
-rw-r--r--src/tests/aoc-2022-08/benches/main.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/tests/aoc-2022-08/benches/main.rs b/src/tests/aoc-2022-08/benches/main.rs
new file mode 100644
index 0000000..ceab4a8
--- /dev/null
+++ b/src/tests/aoc-2022-08/benches/main.rs
@@ -0,0 +1,31 @@
+use aoc_2022_08::HeightMap;
+use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion};
+use rand::{rngs::StdRng, SeedableRng};
+
+fn run_benches(c: &mut Criterion) {
+ let mut rng = StdRng::seed_from_u64(42);
+ for size in [100, 500, 1000, 2000].iter() {
+ c.bench_with_input(BenchmarkId::new("part1", size), size, |b, &n| {
+ b.iter_batched_ref(
+ || HeightMap::gen(&mut rng, n),
+ |map| map.part1(),
+ BatchSize::SmallInput,
+ )
+ });
+
+ c.bench_with_input(BenchmarkId::new("part2", size), size, |b, &n| {
+ b.iter_batched_ref(
+ || HeightMap::gen(&mut rng, n),
+ |map| map.part2(),
+ BatchSize::SmallInput,
+ )
+ });
+ }
+}
+
+criterion_group!(
+ name = benches;
+ config = Criterion::default().sample_size(10);
+ targets = run_benches
+);
+criterion_main!(benches);