Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions benches/generate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import shapely


gdf = gpd.read_file("Utah.geojson.zip", engine="pyogrio")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gdf = gpd.read_file("./bench_data/Utah.geojson", engine="pyogrio")
bounds = shapely.bounds(gdf.geometry)
print(bounds.shape)
buf = bounds.tobytes("C")
with open("bounds.raw", "wb") as f:
with open("./bench_data/bounds.raw", "wb") as f:
f.write(buf)
15 changes: 15 additions & 0 deletions benches/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[project]
name = "geo-index-benches"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
dependencies = [
"geoindex-rs",
"geopandas",
"pyogrio",
"pyarrow",
"numpy",
"requests",
"shapely",
]

4 changes: 4 additions & 0 deletions benches/requirements.txt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer using a basic pyproject.toml here using uv https://docs.astral.sh/uv/, so the benches are repeatable

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
geoindex-rs
geopandas
pyogrio
pyarrow
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're also missing requests, numpy, shapely from the dependency list

42 changes: 42 additions & 0 deletions benches/rtree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import geopandas as gpd
import numpy as np
import shapely
from geoindex_rs import rtree as rt
import timeit
import pyogrio
import requests
def load_data():
path = "./bench_data/nz-building-outlines.parquet"
gdf = gpd.read_parquet(path)
wgs84_gdf = gdf.to_crs("epsg:4326")
bounds = wgs84_gdf.bounds
print(bounds)
return bounds


def construct_wsg84_tree(bounds):
builder = rt.RTreeBuilder(bounds.shape[0])
min_x= np.array(bounds["minx"].values)
min_y=np.array(bounds["miny"].values)
max_x=np.array(bounds["maxx"].values)
max_y=np.array(bounds["maxy"].values)
builder.add(min_x, min_y, max_x, max_y)
return builder.finish()

def construct_shapely_tree(bounds):
tree = shapely.SRTree(bounds.shape[0])
return tree


if __name__ == "__main__":
bounds = load_data()

time = timeit.timeit(stmt='construct_wsg84_tree(bounds)', number=100,
globals=globals())
print(f"Rtree time: {time:.2f} seconds for 100 iterations")






2 changes: 1 addition & 1 deletion benches/rtree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rstar::AABB;
use std::fs::read;

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

Expand Down
39 changes: 39 additions & 0 deletions scripts/bench.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
mkdir -p ./benches/bench_data
cd ./benches/bench_data
if [ ! -f "Utah.geojson.zip" ]
then
echo "Downloading geojson benchmark data..."
wget https://minedbuildings.z5.web.core.windows.net/legacy/usbuildings-v2/Utah.geojson.zip
else
echo "Benchmark data already downloaded"
fi
if [ ! -f "Utah.geojson" ]
then
echo "Unzipping Utah.geojson.zip.."
unzip Utah.geojson.zip
else
echo "Utah.geojson already unzipped "
fi

if [ ! -f "nz-building-outlines.parquet" ]
then
echo "Downloading parquet benchmark data..."
wget https://storage.googleapis.com/open-geodata/linz-examples/nz-building-outlines.parquet
else
echo "Parquet Benchmark data already downloaded"
fi


cd ../
uv venv
source .venv/bin/activate
uv pip install -r pyproject.toml
uv run generate_data.py
cd ../
echo "Running base benchmarks..."
cargo bench --bench rtree
echo "Running benchmarks with rayon feature..."
cargo bench --bench rtree --features rayon
cd ./benches
uv run rtree.py
Loading