-
-
Save slaperche-zenly/32e6e19db4c1a0eda1a19c54a90e7669 to your computer and use it in GitHub Desktop.
Benchmark of a faster h3IsValid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion}; | |
use h3cell; | |
fn bench_hexagons(c: &mut Criterion) { | |
let mut group = c.benchmark_group("Hexagons"); | |
for (resolution, index) in [ | |
0x0807_3fff_ffff_ffff, | |
0x0817_37ff_ffff_ffff, | |
0x0827_34ff_ffff_ffff, | |
0x0837_34ef_ffff_ffff, | |
0x0847_34a9_ffff_ffff, | |
0x0857_34e6_7fff_ffff, | |
0x0867_34e6_4fff_ffff, | |
0x0877_34e6_4dff_ffff, | |
0x0887_34e6_499f_ffff, | |
0x0897_34e6_4993_ffff, | |
0x08a7_34e6_4992_ffff, | |
0x08b7_34e6_4992_9fff, | |
0x08c7_34e6_4992_9dff, | |
0x08d7_34e6_4992_d6ff, | |
0x08e7_34e6_4992_d6df, | |
0x08f7_34e6_4992_d6d8, | |
] | |
.iter() | |
.enumerate() | |
{ | |
group.bench_with_input(BenchmarkId::new("sanic", resolution), index, |b, &index| { | |
b.iter(|| h3cell::is_valid_h3(black_box(index))) | |
}); | |
group.bench_with_input(BenchmarkId::new("h3ron", resolution), index, |b, &index| { | |
b.iter(|| unsafe { h3ron_h3_sys::h3IsValid(black_box(index)) }) | |
}); | |
} | |
group.finish(); | |
} | |
fn bench_pentagons(c: &mut Criterion) { | |
let mut group = c.benchmark_group("Pentagons"); | |
for (resolution, index) in [ | |
0x0810_83ff_ffff_ffff, | |
0x0820_807f_ffff_ffff, | |
0x0830_800f_ffff_ffff, | |
0x0840_8001_ffff_ffff, | |
0x0850_8000_3fff_ffff, | |
0x0860_8000_07ff_ffff, | |
0x0870_8000_00ff_ffff, | |
0x0880_8000_001f_ffff, | |
0x0890_8000_0003_ffff, | |
0x08a0_8000_0000_7fff, | |
0x08b0_8000_0000_0fff, | |
0x08c0_8000_0000_01ff, | |
0x08d0_8000_0000_003f, | |
0x08e0_8000_0000_0007, | |
0x08f0_8000_0000_0000, | |
] | |
.iter() | |
.enumerate() | |
{ | |
group.bench_with_input(BenchmarkId::new("sanic", resolution), index, |b, &index| { | |
b.iter(|| h3cell::is_valid_h3(black_box(index))) | |
}); | |
group.bench_with_input(BenchmarkId::new("h3ron", resolution), index, |b, &index| { | |
b.iter(|| unsafe { h3ron_h3_sys::h3IsValid(black_box(index)) }) | |
}); | |
} | |
group.finish(); | |
} | |
criterion_group!(benches, bench_hexagons, bench_pentagons); | |
criterion_main!(benches); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment