Skip to content

Add moore hilber variant #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Fast Hilbert 2D curve computation using an efficient *Lookup Table (LUT)* and on
* Speedup via lowest order computation (thanks [DoubleHyphen](https://github.com/DoubleHyphen) [PR#2](https://github.com/becheran/fast-hilbert/pull/2))
* Very fast using an efficient 512 Byte *LUT*
* No additional dependency
* Moore variant. See <https://arxiv.org/abs/1311.2868>

Benchmarking the conversion from full 256x256 discrete 2D space to the 1D hilbert space, shows that *fast_hilbert* more than **twice as fast** compared to the fastest 2D hilbert transformation libs written in rust. Benchmarked on a *Intel i5-6400 CPU @ 2.70 GHz, 4 Cores* with *8 GB RAM*:

Expand All @@ -40,3 +41,10 @@ For example the computation of `xy2h(1, 2, 64)` is very fast to compute using `f
| hilbert_2d | 73 ns | 72 ns |
| hilbert_curve | 67 ns | 49 ns |
| hilbert | 690 ns | 680 ns |

The hilbert moore variant has the following performance

| Library | Full | Low Order | High Order |
| ---------------- | ---------: | --------: | ---------: |
| **fast_hilbert** | **1 ms** | **32 ns** | **39 ns** |
| hilbert_2d | 1.8 ms | 59 ns | 59 ns |
57 changes: 57 additions & 0 deletions benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ fn criterion_benchmark(c: &mut Criterion) {
}
})
});
c.bench_function("hilbert_2d_moore", |b| {
b.iter(|| {
for x in 0..n {
for y in 0..n {
black_box(hilbert_2d::xy2h_discrete(
black_box(x),
black_box(y),
black_box(bits),
black_box(hilbert_2d::Variant::Moore),
));
}
}
})
});

c.bench_function("hilbert", |b| {
b.iter(|| {
Expand All @@ -58,6 +72,19 @@ fn criterion_benchmark(c: &mut Criterion) {
}
})
});
c.bench_function("fast_hilbert_moore", |b| {
b.iter(|| {
for x in 0..n {
for y in 0..n {
black_box(fast_hilbert::xy2h_moore(
black_box(x as u32),
black_box(y as u32),
black_box(bits as u8),
));
}
}
})
});

let xy_low: (u32, u32) = (1, 2);
let xy_high: (u32, u32) = (u32::MAX - 1, u32::MAX - 2);
Expand All @@ -73,6 +100,16 @@ fn criterion_benchmark(c: &mut Criterion) {
black_box(fast_hilbert::xy2h(black_box(xy_high.0), black_box(xy_high.1), black_box(order)));
})
});
c.bench_function("fast_hilbert_moore_low", |b| {
b.iter(|| {
black_box(fast_hilbert::xy2h_moore(black_box(xy_low.0), black_box(xy_low.1), black_box(order)));
})
});
c.bench_function("fast_hilbert_moore_high", |b| {
b.iter(|| {
black_box(fast_hilbert::xy2h_moore(black_box(xy_high.0), black_box(xy_high.1), black_box(order)));
})
});
c.bench_function("hilbert_curve_low", |b| {
b.iter(|| {
black_box(hilbert_curve::convert_2d_to_1d(xy_low.0 as usize, xy_low.1 as usize, n));
Expand Down Expand Up @@ -103,6 +140,26 @@ fn criterion_benchmark(c: &mut Criterion) {
));
})
});
c.bench_function("hilbert_2d_moore_low", |b| {
b.iter(|| {
black_box(hilbert_2d::xy2h_discrete(
xy_low.0 as usize,
xy_low.1 as usize,
order as usize,
hilbert_2d::Variant::Moore,
));
})
});
c.bench_function("hilbert_2d_moore_high", |b| {
b.iter(|| {
black_box(hilbert_2d::xy2h_discrete(
xy_high.0 as usize,
xy_high.1 as usize,
order as usize,
hilbert_2d::Variant::Moore,
));
})
});
c.bench_function("hilbert_low", |b| {
b.iter(|| {
let p = hilbert::Point::new(0, &[xy_low.0, xy_low.1]);
Expand Down
Loading