Added inline to dims(), impacts performance greatly.

This commit is contained in:
Olek 2016-12-30 20:23:47 +01:00
parent 89428ed260
commit b85932fe64
2 changed files with 9 additions and 6 deletions

View File

@ -11,11 +11,11 @@ fn gen_random() -> f64 {
rand::thread_rng().gen_range(0., 10000.)
}
fn generate_points(point_count : usize) -> Vec<Point3WithId> {
let mut points : Vec<Point3WithId> = vec![];
fn generate_points(point_count: usize) -> Vec<Point3WithId> {
let mut points: Vec<Point3WithId> = vec![];
for i in 0 .. point_count {
points.push(Point3WithId::new(i as i32, gen_random(),gen_random(),gen_random()));
for i in 0..point_count {
points.push(Point3WithId::new(i as i32, gen_random(), gen_random(), gen_random()));
}
points
@ -54,7 +54,7 @@ fn bench_adding_same_node_to_1000_tree(b: &mut Bencher) {
let mut points = generate_points(len);
let mut tree = kdtree::kdtree::Kdtree::new(&mut points);
let point = Point3WithId::new(-1 as i32, gen_random(),gen_random(),gen_random());
let point = Point3WithId::new(-1 as i32, gen_random(), gen_random(), gen_random());
b.iter(|| {
tree.insert_node(point);
});
@ -62,5 +62,5 @@ fn bench_adding_same_node_to_1000_tree(b: &mut Bencher) {
benchmark_group!(benches, /* bench_creating_1000_node_tree, */ bench_single_loop_times_for_1000_node_tree /*,bench_adding_same_node_to_1000_tree */);
benchmark_group!(benches, bench_creating_1000_node_tree, bench_single_loop_times_for_1000_node_tree,bench_adding_same_node_to_1000_tree);
benchmark_main!(benches);

View File

@ -16,6 +16,7 @@ impl Point3WithId {
}
impl KdtreePointTrait for Point3WithId {
#[inline]
fn dims(&self) -> &[f64] {
return &self.dims;
}
@ -37,6 +38,7 @@ impl Point2WithId {
}
impl KdtreePointTrait for Point2WithId {
#[inline]
fn dims(&self) -> &[f64] {
return &self.dims;
}
@ -58,6 +60,7 @@ impl Point1WithId {
}
impl KdtreePointTrait for Point1WithId {
#[inline]
fn dims(&self) -> &[f64] {
return &self.dims;
}