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: 4 additions & 0 deletions vortex-geo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,9 @@ harness = false
name = "intersection"
harness = false

[[bench]]
name = "hilbert"
harness = false

[lints]
workspace = true
96 changes: 96 additions & 0 deletions vortex-geo/benches/hilbert.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors

//! Microbenchmarks for `vortex.geo.hilbert` with constant `Rect` bounds.
//!
//! Run with `cargo bench -p vortex-geo --bench hilbert`.

#![expect(clippy::unwrap_used)]

use std::sync::LazyLock;

use divan::Bencher;
use divan::counter::ItemsCount;
use mimalloc::MiMalloc;
use vortex_array::ArrayRef;
use vortex_array::Canonical;
use vortex_array::ExecutionCtx;
use vortex_array::IntoArray;
use vortex_array::VortexSessionExecute;
use vortex_array::scalar::Scalar;
use vortex_geo::scalar_fn::hilbert::GeoHilbert;
use vortex_geo::test_harness::MultiPolygonRings;
use vortex_geo::test_harness::geo_session;
use vortex_geo::test_harness::multipolygon_column;
use vortex_geo::test_harness::point_column;
use vortex_geo::test_harness::rect_column;
use vortex_session::VortexSession;

#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;

static SESSION: LazyLock<VortexSession> = LazyLock::new(geo_session);

const ROWS: usize = 1 << 9;

fn main() {
divan::main();
}

fn ordinate(i: usize) -> f64 {
(i.wrapping_mul(2_654_435_761) % 1_000) as f64
}

fn bounds(ctx: &mut ExecutionCtx) -> Scalar {
rect_column(vec![(0.0, 0.0, 1_000.0, 1_000.0)])
.unwrap()
.execute_scalar(0, ctx)
.unwrap()
}

fn hilbert(column: &ArrayRef, bounds: &Scalar, ctx: &mut ExecutionCtx) -> ArrayRef {
GeoHilbert::try_new_array(column.clone(), bounds.clone())
.unwrap()
.into_array()
.execute::<Canonical>(ctx)
.unwrap()
.into_array()
}

fn bench_hilbert(bencher: Bencher, column: ArrayRef) {
let mut ctx = SESSION.create_execution_ctx();
let bounds = bounds(&mut ctx);
bencher
.counter(ItemsCount::new(ROWS))
.bench_local(|| hilbert(&column, &bounds, &mut ctx));
}

#[divan::bench]
fn points(bencher: Bencher) {
let column = point_column(
(0..ROWS).map(ordinate).collect(),
(0..ROWS).map(|row| ordinate(row + 1)).collect(),
)
.unwrap();
bench_hilbert(bencher, column);
}

fn multipolygon(row: usize) -> MultiPolygonRings {
let ring = |offset: usize| {
(0..8)
.map(|vertex| {
(
ordinate(row + offset + vertex),
ordinate(row + offset + vertex + 1),
)
})
.collect()
};
vec![vec![ring(0), ring(8)], vec![ring(16), ring(24)]]
}

#[divan::bench]
fn multipolygons(bencher: Bencher) {
let column = multipolygon_column((0..ROWS).map(multipolygon).collect()).unwrap();
bench_hilbert(bencher, column);
}
2 changes: 2 additions & 0 deletions vortex-geo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::scalar_fn::contains::GeoContains;
use crate::scalar_fn::convex_hull::GeoConvexHull;
use crate::scalar_fn::distance::GeoDistance;
use crate::scalar_fn::envelope::GeoEnvelope;
use crate::scalar_fn::hilbert::GeoHilbert;
use crate::scalar_fn::intersection::GeoIntersection;
use crate::scalar_fn::intersects::GeoIntersects;
use crate::scalar_fn::length::GeoLength;
Expand Down Expand Up @@ -76,6 +77,7 @@ pub fn initialize(session: &VortexSession) {
session.scalar_fns().register(GeoEnvelope);
session.scalar_fns().register(GeoContains);
session.scalar_fns().register(GeoDistance);
session.scalar_fns().register(GeoHilbert);
session.scalar_fns().register(GeoIntersects);
session.scalar_fns().register(GeoIntersection);
session.scalar_fns().register(GeoLength);
Expand Down
Loading