Skip to content

Commit f879d42

Browse files
committed
benches: bench sh script and fixed python bench
Signed-off-by: nuts_rice <[email protected]>
1 parent 9540c05 commit f879d42

File tree

5 files changed

+76
-3
lines changed

5 files changed

+76
-3
lines changed

benches/generate_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import shapely
33

44

5-
gdf = gpd.read_file("Utah.geojson.zip", engine="pyogrio")
5+
gdf = gpd.read_file("./bench_data/8dc58605f9dd484295c7d065694cdc0f_0.geojson", engine="pyogrio")
66
bounds = shapely.bounds(gdf.geometry)
77
print(bounds.shape)
88
buf = bounds.tobytes("C")
9-
with open("bounds.raw", "wb") as f:
9+
with open("./bench_data/bounds.raw", "wb") as f:
1010
f.write(buf)

benches/requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
geoindex-rs
2+
geopandas
3+
pyogrio
4+
pyarrow

benches/rtree.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import geopandas as gpd
2+
import numpy as np
3+
import shapely
4+
from geoindex_rs import rtree as rt
5+
import timeit
6+
import pyogrio
7+
import requests
8+
def load_data():
9+
path = "./bench_data/taxi_zones_4326.parquet"
10+
gdf = gpd.read_parquet(path)
11+
12+
bounds = gdf.bounds
13+
print(bounds)
14+
return bounds
15+
16+
17+
def construct_wsg84_tree(bounds):
18+
builder = rt.RTreeBuilder(bounds.shape[0])
19+
min_x= np.array(bounds["minx"].values)
20+
min_y=np.array(bounds["miny"].values)
21+
max_x=np.array(bounds["maxx"].values)
22+
max_y=np.array(bounds["maxy"].values)
23+
builder.add(min_x, min_y, max_x, max_y)
24+
return builder.finish()
25+
26+
def construct_shapely_tree():
27+
path = "./bench_data/taxi_zones_4326.parquet"
28+
gdf = gpd.read_parquet(path)
29+
tree = shapely.SRTree(gdf.geometry)
30+
return tree
31+
32+
33+
if __name__ == "__main__":
34+
bounds = load_data()
35+
print(timeit.timeit(stmt='construct_wsg84_tree(bounds)', number=100, globals=globals()))
36+
37+
38+
39+
40+

benches/rtree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rstar::AABB;
99
use std::fs::read;
1010

1111
fn load_data() -> Vec<f64> {
12-
let buf = read("benches/bounds.raw").unwrap();
12+
let buf = read("benches/bench_data/bounds.raw").unwrap();
1313
cast_slice(&buf).to_vec()
1414
}
1515

scripts/bench.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
cd ./benches/bench_data
4+
if [ ! -f "8dc58605f9dd484295c7d065694cdc0f_0.geojson" ]
5+
then
6+
echo "Downloading geojson benchmark data..."
7+
wget https://opendata.arcgis.com/datasets/8dc58605f9dd484295c7d065694cdc0f_0.geojson
8+
else
9+
echo "Benchmark data already downloaded"
10+
fi
11+
if [ ! -f "taxi_zones_4326.parquet" ]
12+
then
13+
echo "Downloading parquet benchmark data..."
14+
wget https://data.source.coop/cholmes/nyc-taxi-zones/taxi_zones_4326.parquet
15+
else
16+
echo "Parquet Benchmark data already downloaded"
17+
fi
18+
19+
20+
cd ../
21+
pip install -r requirements.txt
22+
python generate_data.py
23+
cd ../
24+
echo "Running base benchmarks..."
25+
cargo bench --bench rtree
26+
echo "Running benchmarks with rayon feature..."
27+
cargo bench --bench rtree --features rayon
28+
cd ./benches
29+
python rtree.py

0 commit comments

Comments
 (0)