@@ -12,6 +12,7 @@ use geo::{Coord, LineString, MapCoords, Polygon};
1212use rand:: { Rng , SeedableRng } ;
1313use rand_hc:: Hc128Rng ;
1414
15+ use rstar:: primitives:: CachedEnvelope ;
1516use rstar:: { RStarInsertionStrategy , RTree , RTreeParams } ;
1617
1718use criterion:: Criterion ;
@@ -53,15 +54,30 @@ fn bulk_load_comparison(c: &mut Criterion) {
5354}
5455
5556fn bulk_load_complex_geom ( c : & mut Criterion ) {
56- c. bench_function ( "Bulk load complex geom" , move |b| {
57- let polys: Vec < _ > = create_random_polygons ( DEFAULT_BENCHMARK_TREE_SIZE , 4096 , SEED_1 ) ;
57+ c. bench_function ( "Bulk load complex geo-types geom" , move |b| {
58+ let polys: Vec < _ > =
59+ create_random_polygons ( DEFAULT_BENCHMARK_TREE_SIZE , 4096 , SEED_1 ) . collect ( ) ;
5860
5961 b. iter ( || {
6062 RTree :: < Polygon < f64 > , Params > :: bulk_load_with_params ( polys. clone ( ) ) ;
6163 } ) ;
6264 } ) ;
6365}
6466
67+ fn bulk_load_complex_geom_cached ( c : & mut Criterion ) {
68+ c. bench_function (
69+ "Bulk load complex geo-types geom with cached envelope" ,
70+ move |b| {
71+ let cached: Vec < _ > = create_random_polygons ( DEFAULT_BENCHMARK_TREE_SIZE , 4096 , SEED_1 )
72+ . map ( CachedEnvelope :: new)
73+ . collect ( ) ;
74+ b. iter ( || {
75+ RTree :: < CachedEnvelope < _ > , Params > :: bulk_load_with_params ( cached. clone ( ) ) ;
76+ } ) ;
77+ } ,
78+ ) ;
79+ }
80+
6581fn tree_creation_quality ( c : & mut Criterion ) {
6682 const SIZE : usize = 100_000 ;
6783 let points: Vec < _ > = create_random_points ( SIZE , SEED_1 ) ;
@@ -112,6 +128,7 @@ criterion_group!(
112128 bulk_load_baseline,
113129 bulk_load_comparison,
114130 bulk_load_complex_geom,
131+ bulk_load_complex_geom_cached,
115132 tree_creation_quality,
116133 locate_successful,
117134 locate_unsuccessful
@@ -123,23 +140,25 @@ fn create_random_points(num_points: usize, seed: &[u8; 32]) -> Vec<[f64; 2]> {
123140 ( 0 ..num_points) . map ( |_| rng. gen ( ) ) . collect ( )
124141}
125142
126- fn create_random_polygons ( num_points : usize , size : usize , seed : & [ u8 ; 32 ] ) -> Vec < Polygon < f64 > > {
143+ fn create_random_polygons (
144+ num_points : usize ,
145+ size : usize ,
146+ seed : & [ u8 ; 32 ] ,
147+ ) -> impl Iterator < Item = Polygon < f64 > > {
127148 let mut rng = Hc128Rng :: from_seed ( * seed) ;
128149 let base_polygon = circular_polygon ( size) ;
129150
130- ( 0 ..num_points)
131- . map ( |_| {
132- let [ scale_x, scale_y] : [ f64 ; 2 ] = rng. gen ( ) ;
133- let [ shift_x, shift_y] : [ f64 ; 2 ] = rng. gen ( ) ;
134- base_polygon. clone ( ) . map_coords ( |c| Coord {
135- x : ( shift_x + c. x ) * scale_x,
136- y : ( shift_y + c. y ) * scale_y,
137- } )
151+ ( 0 ..num_points) . map ( move |_| {
152+ let [ scale_x, scale_y] : [ f64 ; 2 ] = rng. gen ( ) ;
153+ let [ shift_x, shift_y] : [ f64 ; 2 ] = rng. gen ( ) ;
154+ base_polygon. clone ( ) . map_coords ( |c| Coord {
155+ x : ( shift_x + c. x ) * scale_x,
156+ y : ( shift_y + c. y ) * scale_y,
138157 } )
139- . collect ( )
158+ } )
140159}
141160
142- pub fn circular_polygon ( steps : usize ) -> Polygon < f64 > {
161+ fn circular_polygon ( steps : usize ) -> Polygon < f64 > {
143162 let delta = 2. * PI / steps as f64 ;
144163 let r = 1.0 ;
145164
0 commit comments