From 8d4679f7ef988e5319d0b5fc499868b25d11a91e Mon Sep 17 00:00:00 2001 From: James McBride Date: Fri, 24 Sep 2021 08:59:28 -0700 Subject: [PATCH] PERF: Add new overlay benchmarks (#2118) Motivated by the pretty serious performance regression on overlays I accidentally introduced in #1582, and reported in #2089, here's a new benchmark for overlays that makes the regression more apparent than the existing overlay benchmarks. --- benchmarks/overlay.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/benchmarks/overlay.py b/benchmarks/overlay.py index 7f1620a..c9cddef 100644 --- a/benchmarks/overlay.py +++ b/benchmarks/overlay.py @@ -1,10 +1,11 @@ from geopandas import GeoDataFrame, GeoSeries, read_file, datasets, overlay -from shapely.geometry import Polygon +import numpy as np +from shapely.geometry import Point, Polygon class Countries: - param_names = ['op'] + param_names = ['how'] params = [('intersection', 'union', 'identity', 'symmetric_difference', 'difference')] @@ -20,13 +21,13 @@ class Countries: self.countries = countries self.capitals = capitals - def time_overlay(self, op): - overlay(self.countries, self.capitals, how=op) + def time_overlay(self, how): + overlay(self.countries, self.capitals, how=how) class Small: - param_names = ['op'] + param_names = ['how'] params = [('intersection', 'union', 'identity', 'symmetric_difference', 'difference')] @@ -41,5 +42,24 @@ class Small: self.df1, self.df2 = df1, df2 - def time_overlay(self, op): - overlay(self.df1, self.df2, how=op) + def time_overlay(self, how): + overlay(self.df1, self.df2, how=how) + + +class ManyPoints: + + param_names = ['how'] + params = [('intersection', 'union', 'identity', 'symmetric_difference', + 'difference')] + + def setup(self, *args): + + points = GeoDataFrame(geometry=[Point(i, i) for i in range(1000)]) + base = np.array([[0, 0], [0, 100], [100, 100], [100, 0]]) + polys = GeoDataFrame( + geometry=[Polygon(base + i * 100) for i in range(10)]) + + self.df1, self.df2 = points, polys + + def time_overlay(self, how): + overlay(self.df1, self.df2, how=how)