-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* use critrion instead of feature test, since it is unstablized * fixes * warnings --------- Co-authored-by: Zhen Liu <[email protected]>
- Loading branch information
Showing
2 changed files
with
70 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,138 +1,153 @@ | ||
#![feature(test)] | ||
extern crate criterion; | ||
extern crate kdtree; | ||
extern crate rand; | ||
extern crate test; | ||
|
||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use kdtree::distance::squared_euclidean; | ||
use kdtree::KdTree; | ||
use test::Bencher; | ||
|
||
fn rand_data() -> ([f64; 3], f64) { | ||
rand::random() | ||
} | ||
|
||
#[bench] | ||
fn bench_add_to_kdtree_with_1k_3d_points(b: &mut Bencher) { | ||
fn bench_add_to_kdtree_with_1k_3d_points(c: &mut Criterion) { | ||
let len = 1000usize; | ||
let point = rand_data(); | ||
let mut points = vec![]; | ||
let mut kdtree = KdTree::with_capacity(3, 16); | ||
for _ in 0..len { | ||
points.push(rand_data()); | ||
} | ||
for i in 0..points.len() { | ||
kdtree.add(&points[i].0, points[i].1).unwrap(); | ||
for point in points.iter() { | ||
kdtree.add(&point.0, point.1).unwrap(); | ||
} | ||
b.iter(|| kdtree.add(&point.0, point.1).unwrap()); | ||
c.bench_function("bench_add_to_kdtree_with_1k_3d_points", |b| { | ||
b.iter(|| kdtree.add(&point.0, point.1).unwrap()); | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn bench_nearest_from_kdtree_with_1k_3d_points(b: &mut Bencher) { | ||
fn bench_nearest_from_kdtree_with_1k_3d_points(c: &mut Criterion) { | ||
let len = 1000usize; | ||
let point = rand_data(); | ||
let mut points = vec![]; | ||
let mut kdtree = KdTree::with_capacity(3, 16); | ||
for _ in 0..len { | ||
points.push(rand_data()); | ||
} | ||
for i in 0..points.len() { | ||
kdtree.add(&points[i].0, points[i].1).unwrap(); | ||
for point in points.iter() { | ||
kdtree.add(&point.0, point.1).unwrap(); | ||
} | ||
b.iter(|| kdtree.nearest(&point.0, 8, &squared_euclidean).unwrap()); | ||
c.bench_function("bench_nearest_from_kdtree_with_1k_3d_points", |b| { | ||
b.iter(|| kdtree.nearest(&point.0, 8, &squared_euclidean).unwrap()); | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn bench_within_2k_data_01_radius(b: &mut Bencher) { | ||
fn bench_within_2k_data_01_radius(c: &mut Criterion) { | ||
let len = 2000usize; | ||
let point = rand_data(); | ||
let mut points = vec![]; | ||
let mut kdtree = KdTree::with_capacity(3, 16); | ||
for _ in 0..len { | ||
points.push(rand_data()); | ||
} | ||
for i in 0..points.len() { | ||
kdtree.add(&points[i].0, points[i].1).unwrap(); | ||
for point in points.iter() { | ||
kdtree.add(&point.0, point.1).unwrap(); | ||
} | ||
|
||
b.iter(|| kdtree.within(&point.0, 0.1, &squared_euclidean).unwrap()); | ||
c.bench_function("bench_within_2k_data_01_radius", |b| { | ||
b.iter(|| kdtree.within(&point.0, 0.1, &squared_euclidean).unwrap()); | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn bench_within_2k_data_02_radius(b: &mut Bencher) { | ||
fn bench_within_2k_data_02_radius(c: &mut Criterion) { | ||
let len = 2000usize; | ||
let point = rand_data(); | ||
let mut points = vec![]; | ||
let mut kdtree = KdTree::with_capacity(3, 16); | ||
for _ in 0..len { | ||
points.push(rand_data()); | ||
} | ||
for i in 0..points.len() { | ||
kdtree.add(&points[i].0, points[i].1).unwrap(); | ||
for point in points.iter() { | ||
kdtree.add(&point.0, point.1).unwrap(); | ||
} | ||
|
||
b.iter(|| kdtree.within(&point.0, 0.2, &squared_euclidean).unwrap()); | ||
c.bench_function("bench_within_2k_data_02_radius", |b| { | ||
b.iter(|| kdtree.within(&point.0, 0.2, &squared_euclidean).unwrap()); | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn bench_within_unsorted_2k_data_01_radius(b: &mut Bencher) { | ||
fn bench_within_unsorted_2k_data_01_radius(c: &mut Criterion) { | ||
let len = 2000usize; | ||
let point = rand_data(); | ||
let mut points = vec![]; | ||
let mut kdtree = KdTree::with_capacity(3, 16); | ||
for _ in 0..len { | ||
points.push(rand_data()); | ||
} | ||
for i in 0..points.len() { | ||
kdtree.add(&points[i].0, points[i].1).unwrap(); | ||
for point in points.iter() { | ||
kdtree.add(&point.0, point.1).unwrap(); | ||
} | ||
|
||
b.iter(|| kdtree.within_unsorted(&point.0, 0.1, &squared_euclidean).unwrap()); | ||
c.bench_function("bench_within_unsorted_2k_data_01_radius", |b| { | ||
b.iter(|| kdtree.within_unsorted(&point.0, 0.1, &squared_euclidean).unwrap()); | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn bench_within_unsorted_2k_data_02_radius(b: &mut Bencher) { | ||
fn bench_within_unsorted_2k_data_02_radius(c: &mut Criterion) { | ||
let len = 2000usize; | ||
let point = rand_data(); | ||
let mut points = vec![]; | ||
let mut kdtree = KdTree::with_capacity(3, 16); | ||
for _ in 0..len { | ||
points.push(rand_data()); | ||
} | ||
for i in 0..points.len() { | ||
kdtree.add(&points[i].0, points[i].1).unwrap(); | ||
for point in points.iter() { | ||
kdtree.add(&point.0, point.1).unwrap(); | ||
} | ||
|
||
b.iter(|| kdtree.within_unsorted(&point.0, 0.2, &squared_euclidean).unwrap()); | ||
c.bench_function("bench_within_unsorted_2k_data_02_radius", |b| { | ||
b.iter(|| kdtree.within_unsorted(&point.0, 0.2, &squared_euclidean).unwrap()); | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn bench_within_count_2k_data_01_radius(b: &mut Bencher) { | ||
fn bench_within_count_2k_data_01_radius(c: &mut Criterion) { | ||
let len = 2000usize; | ||
let point = rand_data(); | ||
let mut points = vec![]; | ||
let mut kdtree = KdTree::with_capacity(3, 16); | ||
for _ in 0..len { | ||
points.push(rand_data()); | ||
} | ||
for i in 0..points.len() { | ||
kdtree.add(&points[i].0, points[i].1).unwrap(); | ||
for point in points.iter() { | ||
kdtree.add(&point.0, point.1).unwrap(); | ||
} | ||
|
||
b.iter(|| kdtree.within_count(&point.0, 0.1, &squared_euclidean).unwrap()); | ||
c.bench_function("bench_within_count_2k_data_01_radius", |b| { | ||
b.iter(|| kdtree.within_count(&point.0, 0.1, &squared_euclidean).unwrap()); | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn bench_within_count_2k_data_02_radius(b: &mut Bencher) { | ||
fn bench_within_count_2k_data_02_radius(c: &mut Criterion) { | ||
let len = 2000usize; | ||
let point = rand_data(); | ||
let mut points = vec![]; | ||
let mut kdtree = KdTree::with_capacity(3, 16); | ||
for _ in 0..len { | ||
points.push(rand_data()); | ||
} | ||
for i in 0..points.len() { | ||
kdtree.add(&points[i].0, points[i].1).unwrap(); | ||
for point in points.iter() { | ||
kdtree.add(&point.0, point.1).unwrap(); | ||
} | ||
|
||
b.iter(|| kdtree.within_count(&point.0, 0.2, &squared_euclidean).unwrap()); | ||
c.bench_function("bench_within_count_2k_data_02_radius", |b| { | ||
b.iter(|| kdtree.within_count(&point.0, 0.2, &squared_euclidean).unwrap()); | ||
}); | ||
} | ||
|
||
criterion_group!( | ||
benches, | ||
bench_add_to_kdtree_with_1k_3d_points, | ||
bench_nearest_from_kdtree_with_1k_3d_points, | ||
bench_within_2k_data_01_radius, | ||
bench_within_2k_data_02_radius, | ||
bench_within_unsorted_2k_data_01_radius, | ||
bench_within_unsorted_2k_data_02_radius, | ||
bench_within_count_2k_data_01_radius, | ||
bench_within_count_2k_data_02_radius, | ||
); | ||
|
||
criterion_main!(benches); |