aboutsummaryrefslogtreecommitdiff
path: root/benches
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2023-05-13 21:49:21 +0200
committerDaniel Schadt <kingdread@gmx.de>2023-05-13 21:49:21 +0200
commit62e7ee33b1c0f98f480067819fdcc567539fbb97 (patch)
tree342961fe18d382dace735742a3b0873eaa426148 /benches
parentff7c55ecdab6300e82003f99020f44f45d0943d8 (diff)
downloadhittekaart-62e7ee33b1c0f98f480067819fdcc567539fbb97.tar.gz
hittekaart-62e7ee33b1c0f98f480067819fdcc567539fbb97.tar.bz2
hittekaart-62e7ee33b1c0f98f480067819fdcc567539fbb97.zip
add more benchmarks
Diffstat (limited to 'benches')
-rw-r--r--benches/hittebench.rs42
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);