futz
This commit is contained in:
parent
c9bab10f6b
commit
0a54cad11e
2 changed files with 39 additions and 40 deletions
|
|
@ -1,41 +1,43 @@
|
||||||
#[path = "shared.rs"]
|
|
||||||
mod shared;
|
|
||||||
use std::hint::black_box;
|
use std::hint::black_box;
|
||||||
|
|
||||||
use autobarts::{geom::Point, spindex::RStarTree};
|
use autobarts::{geom::Point, spindex::RStarTree};
|
||||||
use bevy::math::Vec2;
|
use bevy::math::Vec2;
|
||||||
use criterion::{Criterion, criterion_group};
|
use criterion::{Criterion, criterion_group};
|
||||||
use shared::*;
|
|
||||||
|
//
|
||||||
|
// Benchmark Parameters
|
||||||
|
//
|
||||||
|
pub const BENCH_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(10);
|
||||||
|
pub const BENCH_NUM_INSERT: i32 = 50_000;
|
||||||
|
pub const BENCH_NODE_CAPACITY: usize = 5;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Data Generation Functions (Raw Data)
|
||||||
|
//
|
||||||
|
pub fn generate_2d_data() -> Vec<Point> {
|
||||||
|
let data: Vec<Point> = (0..BENCH_NUM_INSERT)
|
||||||
|
.map(|i| {
|
||||||
|
let point = bevy::prelude::Vec2::new(i as f32, i as f32);
|
||||||
|
|
||||||
|
Point {
|
||||||
|
point,
|
||||||
|
entity: bevy::prelude::Entity::PLACEHOLDER,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
data
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure Criterion with a timeout for benchmarks
|
||||||
|
pub fn configure_criterion() -> Criterion {
|
||||||
|
Criterion::default()
|
||||||
|
.measurement_time(BENCH_TIMEOUT)
|
||||||
|
.sample_size(10)
|
||||||
|
}
|
||||||
|
|
||||||
const BENCH_RANGE_RADIUS: f32 = 30.0;
|
const BENCH_RANGE_RADIUS: f32 = 30.0;
|
||||||
|
|
||||||
// Configure Criterion with our benchmark timeout.
|
|
||||||
pub fn configure_criterion() -> Criterion {
|
|
||||||
Criterion::default().measurement_time(BENCH_TIMEOUT)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A generic helper function for range search benchmarks.
|
|
||||||
///
|
|
||||||
/// The lifetime `'a` ties the lifetime of the tree reference and the return
|
|
||||||
/// value. The closure `search_fn` must return a value whose lifetime is at
|
|
||||||
/// least `'a`.
|
|
||||||
fn bench_range_search<'a, T, Q, R>(
|
|
||||||
name: &str,
|
|
||||||
tree: &'a T,
|
|
||||||
query: &Q,
|
|
||||||
search_fn: impl Fn(&'a T, &Q, f32) -> R,
|
|
||||||
cc: &mut Criterion,
|
|
||||||
) where
|
|
||||||
R: 'a,
|
|
||||||
{
|
|
||||||
cc.bench_function(name, |b| {
|
|
||||||
b.iter(|| {
|
|
||||||
let res = search_fn(tree, query, BENCH_RANGE_RADIUS);
|
|
||||||
black_box(res)
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
fn benchmark_range_rstartree_2d(_c: &mut Criterion) {
|
fn benchmark_range_rstartree_2d(_c: &mut Criterion) {
|
||||||
let points = generate_2d_data();
|
let points = generate_2d_data();
|
||||||
let mut tree = RStarTree::new(BENCH_NODE_CAPACITY);
|
let mut tree = RStarTree::new(BENCH_NODE_CAPACITY);
|
||||||
|
|
@ -65,13 +67,12 @@ fn benchmark_range_bbox_rstartree_2d(_c: &mut Criterion) {
|
||||||
4.0 * Vec2::splat(BENCH_RANGE_RADIUS),
|
4.0 * Vec2::splat(BENCH_RANGE_RADIUS),
|
||||||
);
|
);
|
||||||
let mut cc = configure_criterion();
|
let mut cc = configure_criterion();
|
||||||
bench_range_search(
|
cc.bench_function("range_rstartree_2d", |b| {
|
||||||
"range_rstartree_bbox_2d",
|
b.iter(|| {
|
||||||
&tree,
|
let res = tree.range_search_bbox(&query_rect);
|
||||||
&query_rect,
|
black_box(res)
|
||||||
|t, q, _| t.range_search_bbox(q),
|
})
|
||||||
&mut cc,
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
criterion_group!(
|
criterion_group!(
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use bevy::{
|
use bevy::{
|
||||||
math::bounding::{Aabb2d, BoundingVolume, IntersectsVolume},
|
math::bounding::{Aabb2d, BoundingVolume, IntersectsVolume},
|
||||||
prelude::*,
|
prelude::Vec2,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::geom::Point;
|
use crate::geom::Point;
|
||||||
|
|
@ -143,8 +143,6 @@ impl RStarTree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RStarTree {}
|
|
||||||
|
|
||||||
fn entries_mbr(entries: &[Entry]) -> Option<Aabb2d> {
|
fn entries_mbr(entries: &[Entry]) -> Option<Aabb2d> {
|
||||||
let mut iter = entries.iter();
|
let mut iter = entries.iter();
|
||||||
let first = *iter.next()?.mbr();
|
let first = *iter.next()?.mbr();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue