diff options
-rw-r--r-- | benches/hittebench.rs | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/benches/hittebench.rs b/benches/hittebench.rs index fefb07f..268df8f 100644 --- a/benches/hittebench.rs +++ b/benches/hittebench.rs @@ -1,23 +1,49 @@ -use criterion::{criterion_group, criterion_main, Criterion}; +use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion}; use hittekaart::{ gpx, - renderer::{self, heatmap}, + renderer::{self, heatmap, marktile, tilehunt, Renderer}, }; static BENCH_DATA: &str = include_str!("bench.gpx"); -pub fn criterion_benchmark(c: &mut Criterion) { - c.bench_function("extract_from_str", |b| { - b.iter(|| gpx::extract_from_str(BENCH_DATA).unwrap()) +fn benchmark<R>(c: &mut Criterion, name: &str, renderer: R) +where + R: Renderer, + R::Prepared: Clone, +{ + let data = vec![gpx::extract_from_str(BENCH_DATA).unwrap()]; + + c.bench_function(&format!("{name}/Renderer::prepare"), |b| { + b.iter(|| renderer::prepare(&renderer, 19, &data, || Ok(())).unwrap()); }); - let data = vec![gpx::extract_from_str(BENCH_DATA).unwrap()]; + let prepared = renderer::prepare(&renderer, 19, &data, || Ok(())).unwrap(); - c.bench_function("render_heatcounter", |b| { - b.iter(|| renderer::prepare(&heatmap::Renderer, 19, &data, || Ok(()))); + c.bench_function(&format!("{name}/Renderer::colorize"), |b| { + b.iter_batched( + || prepared.clone(), + |prepared| { + renderer::colorize(&renderer, prepared, |tile| { + black_box(tile); + Ok(()) + }) + .unwrap(); + }, + BatchSize::SmallInput, + ); }); } +fn criterion_benchmark(c: &mut Criterion) { + c.bench_function("extract_from_str", |b| { + b.iter(|| gpx::extract_from_str(BENCH_DATA).unwrap()) + }); + + benchmark(c, "heatmap", heatmap::Renderer); + benchmark(c, "marktile", marktile::Renderer); + benchmark(c, "tilehunt", tilehunt::Renderer::new(19)); +} + criterion_group!(benches, criterion_benchmark); criterion_main!(benches); |