Skip to content

Commit 2f46e5b

Browse files
committed
Add benchmark for flat neighborhood search
1 parent 096cab2 commit 2f46e5b

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

splashsurf_lib/benches/benches/bench_neighborhood.rs

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use criterion::{Criterion, criterion_group};
22
use nalgebra::Vector3;
33
use splashsurf_lib::io;
4+
use splashsurf_lib::neighborhood_search::FlatNeighborhoodList;
45
use splashsurf_lib::{Aabb3d, neighborhood_search};
56
use std::time::Duration;
67

@@ -10,7 +11,8 @@ static COMPACT_SUPPORT_RADIUS: f64 = 4.0 * PARTICLE_RADIUS;
1011
//static NUM_PARTICLES: Option<usize> = Some(800);
1112
static NUM_PARTICLES: Option<usize> = None;
1213

13-
static PARTICLE_FILE: &str = "../data/bunny_frame_14_7705_particles.vtk";
14+
//static PARTICLE_FILE: &str = "../data/bunny_frame_14_7705_particles.vtk";
15+
static PARTICLE_FILE: &str = "../data/dam_break_frame_23_24389_particles.bgeo";
1416

1517
fn particle_subset(particle_positions: &[Vector3<f32>]) -> &[Vector3<f32>] {
1618
if let Some(n_particles) = NUM_PARTICLES {
@@ -21,8 +23,7 @@ fn particle_subset(particle_positions: &[Vector3<f32>]) -> &[Vector3<f32>] {
2123
}
2224

2325
pub fn neighborhood_search_naive(c: &mut Criterion) {
24-
let particle_positions: &Vec<Vector3<f32>> =
25-
&io::vtk_format::particles_from_vtk(PARTICLE_FILE).unwrap();
26+
let particle_positions: &Vec<Vector3<f32>> = &io::particles_from_file(PARTICLE_FILE).unwrap();
2627
let particle_positions = particle_subset(particle_positions.as_slice());
2728

2829
let mut group = c.benchmark_group("neighborhood_search");
@@ -45,9 +46,8 @@ pub fn neighborhood_search_naive(c: &mut Criterion) {
4546
group.finish();
4647
}
4748

48-
pub fn neighborhood_search_spatial_hashing(c: &mut Criterion) {
49-
let particle_positions: &Vec<Vector3<f32>> =
50-
&io::vtk_format::particles_from_vtk(PARTICLE_FILE).unwrap();
49+
pub fn neighborhood_search_spatial_hashing_seq(c: &mut Criterion) {
50+
let particle_positions: &Vec<Vector3<f32>> = &io::particles_from_file(PARTICLE_FILE).unwrap();
5151
let particle_positions = particle_subset(particle_positions.as_slice());
5252

5353
let mut domain = Aabb3d::from_points(particle_positions);
@@ -59,7 +59,7 @@ pub fn neighborhood_search_spatial_hashing(c: &mut Criterion) {
5959
group.measurement_time(Duration::from_secs(10));
6060

6161
let mut neighborhood_lists = Vec::with_capacity(particle_positions.len());
62-
group.bench_function("neighborhood_search_spatial_hashing", move |b| {
62+
group.bench_function("neighborhood_search_spatial_hashing_seq", move |b| {
6363
b.iter(|| {
6464
neighborhood_lists.clear();
6565
neighborhood_search::neighborhood_search_spatial_hashing::<i32, f32>(
@@ -75,8 +75,7 @@ pub fn neighborhood_search_spatial_hashing(c: &mut Criterion) {
7575
}
7676

7777
pub fn neighborhood_search_spatial_hashing_parallel(c: &mut Criterion) {
78-
let particle_positions: &Vec<Vector3<f32>> =
79-
&io::vtk_format::particles_from_vtk(PARTICLE_FILE).unwrap();
78+
let particle_positions: &Vec<Vector3<f32>> = &io::particles_from_file(PARTICLE_FILE).unwrap();
8079
let particle_positions = particle_subset(particle_positions.as_slice());
8180

8281
let mut domain = Aabb3d::from_points(particle_positions);
@@ -103,9 +102,38 @@ pub fn neighborhood_search_spatial_hashing_parallel(c: &mut Criterion) {
103102
group.finish();
104103
}
105104

105+
pub fn neighborhood_search_spatial_hashing_seq_flat(c: &mut Criterion) {
106+
let particle_positions: &Vec<Vector3<f32>> = &io::particles_from_file(PARTICLE_FILE).unwrap();
107+
let particle_positions = particle_subset(particle_positions.as_slice());
108+
109+
let mut domain = Aabb3d::from_points(particle_positions);
110+
domain.grow_uniformly(COMPACT_SUPPORT_RADIUS as f32);
111+
112+
let mut group = c.benchmark_group("neighborhood_search");
113+
group.sample_size(100);
114+
group.warm_up_time(Duration::from_secs(3));
115+
group.measurement_time(Duration::from_secs(10));
116+
117+
let mut neighborhood_lists = FlatNeighborhoodList::default();
118+
group.bench_function("neighborhood_search_spatial_hashing_seq_flat", move |b| {
119+
b.iter(|| {
120+
neighborhood_search::neighborhood_search_spatial_hashing_flat_filtered::<i32, f32>(
121+
&domain,
122+
particle_positions,
123+
COMPACT_SUPPORT_RADIUS as f32,
124+
&mut neighborhood_lists,
125+
|_| true,
126+
);
127+
})
128+
});
129+
130+
group.finish();
131+
}
132+
106133
criterion_group!(
107134
bench_neighborhood,
108135
neighborhood_search_naive,
109-
neighborhood_search_spatial_hashing,
136+
neighborhood_search_spatial_hashing_seq,
110137
neighborhood_search_spatial_hashing_parallel,
138+
neighborhood_search_spatial_hashing_seq_flat,
111139
);

0 commit comments

Comments
 (0)