Skip to content

Commit 49cfef2

Browse files
committed
add py bench
Change-Id: I82756252fbb0af27941d3af0eee92af1da935410
1 parent a58b480 commit 49cfef2

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

python/python/benchmarks/test_search.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,3 +505,64 @@ def test_late_materialization(test_dataset, benchmark, use_index):
505505
filter=f"{column} = 0",
506506
batch_size=32,
507507
)
508+
509+
510+
@pytest.fixture(scope="module")
511+
def test_geo_dataset(tmpdir_factory):
512+
from geoarrow.rust.core import (
513+
point,
514+
points,
515+
)
516+
517+
num_rows = 1_000_000
518+
points_2d = points(
519+
[np.random.randn(num_rows) * 100, np.random.randn(num_rows) * 100]
520+
)
521+
522+
schema = pa.schema(
523+
[
524+
pa.field(point("xy")).with_name("points"),
525+
]
526+
)
527+
table = pa.Table.from_arrays([points_2d], schema=schema)
528+
uri = str(tmpdir_factory.mktemp("test_geo_dataset"))
529+
lance.write_dataset(table, uri)
530+
ds = lance.dataset(uri)
531+
return ds
532+
533+
534+
@pytest.mark.benchmark(group="geo")
535+
@pytest.mark.parametrize(
536+
"use_index",
537+
(False, True),
538+
ids=["no_index", "with_index"],
539+
)
540+
def test_geo_rtree(test_geo_dataset, benchmark, use_index):
541+
if use_index:
542+
test_geo_dataset.create_scalar_index(
543+
column="points",
544+
index_type="RTREE",
545+
replace=True,
546+
)
547+
548+
print(
549+
test_geo_dataset.scanner(
550+
columns=["points"],
551+
filter="""
552+
St_Contains(points,
553+
ST_GeomFromText('POLYGON (( 0 0, 2 0, 0 2, 2 2, 0 0 ))'))
554+
""",
555+
batch_size=32,
556+
use_scalar_index=use_index,
557+
).explain_plan(True)
558+
)
559+
benchmark(
560+
test_geo_dataset.to_table,
561+
columns=["points"],
562+
filter="""
563+
St_Contains(points,
564+
ST_GeomFromText('POLYGON (( 0 0, 2 0, 0 2, 2 2, 0 0 ))'))
565+
""",
566+
batch_size=32,
567+
use_scalar_index=use_index,
568+
)

rust/lance-index/benches/geo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ async fn rect_search_rtree(
111111

112112
fn bench_rtree(c: &mut Criterion) {
113113
let rt = tokio::runtime::Builder::new_multi_thread().build().unwrap();
114-
let num_points = 1_000_000;
114+
let num_rows = 1_000_000;
115115

116116
let tempdir = tempfile::tempdir().unwrap();
117117
let index_dir = Path::from_filesystem_path(tempdir.path()).unwrap();
@@ -123,7 +123,7 @@ fn bench_rtree(c: &mut Criterion) {
123123
))
124124
});
125125

126-
let geo_data = rt.block_on(async { black_box(generate_geo_data(num_points, 42)) });
126+
let geo_data = rt.block_on(async { black_box(generate_geo_data(num_rows, 42)) });
127127

128128
let mut group = c.benchmark_group("RTree");
129129
group.sample_size(10);

0 commit comments

Comments
 (0)