-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1197 from georust/mkirk/prepared-geom
Add `PreparedGeometry` to speed up repeated `Relate` operations.
- Loading branch information
Showing
23 changed files
with
714 additions
and
273 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
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use geo::algorithm::Relate; | ||
use geo::PreparedGeometry; | ||
use geo_types::MultiPolygon; | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
c.bench_function("relate prepared polygons", |bencher| { | ||
let plot_polygons: MultiPolygon = geo_test_fixtures::nl_plots(); | ||
let zone_polygons = geo_test_fixtures::nl_zones(); | ||
|
||
bencher.iter(|| { | ||
let mut intersects = 0; | ||
let mut non_intersects = 0; | ||
|
||
let plot_polygons = plot_polygons | ||
.iter() | ||
.map(PreparedGeometry::from) | ||
.collect::<Vec<_>>(); | ||
|
||
let zone_polygons = zone_polygons | ||
.iter() | ||
.map(PreparedGeometry::from) | ||
.collect::<Vec<_>>(); | ||
|
||
for a in &plot_polygons { | ||
for b in &zone_polygons { | ||
if criterion::black_box(a.relate(b).is_intersects()) { | ||
intersects += 1; | ||
} else { | ||
non_intersects += 1; | ||
} | ||
} | ||
} | ||
|
||
assert_eq!(intersects, 974); | ||
assert_eq!(non_intersects, 27782); | ||
}); | ||
}); | ||
|
||
c.bench_function("relate unprepared polygons", |bencher| { | ||
let plot_polygons: MultiPolygon = geo_test_fixtures::nl_plots(); | ||
let zone_polygons = geo_test_fixtures::nl_zones(); | ||
|
||
bencher.iter(|| { | ||
let mut intersects = 0; | ||
let mut non_intersects = 0; | ||
|
||
for a in &plot_polygons { | ||
for b in &zone_polygons { | ||
if criterion::black_box(a.relate(b).is_intersects()) { | ||
intersects += 1; | ||
} else { | ||
non_intersects += 1; | ||
} | ||
} | ||
} | ||
|
||
assert_eq!(intersects, 974); | ||
assert_eq!(non_intersects, 27782); | ||
}); | ||
}); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
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
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
Oops, something went wrong.