Skip to content

Instantly share code, notes, and snippets.

@slaperche-zenly
Created February 13, 2022 05:14
Show Gist options
  • Save slaperche-zenly/21f59b36dc954b20295193ed8bba464d to your computer and use it in GitHub Desktop.
Save slaperche-zenly/21f59b36dc954b20295193ed8bba464d to your computer and use it in GitHub Desktop.
Compare the execution time with a mix of valid and invalid values.
use std::time::Instant;
fn main() {
let mut valid = 0;
let start = Instant::now();
for i in 0..=0x7fff_ffff_u32 {
let cell = 0x0880_0000_001f_ffff | (u64::from(i) << 21);
let is_valid = h3cell::is_valid_h3(cell);
valid += is_valid as usize;
}
let duration = start.elapsed();
println!("found {} valid cells in {:?}", valid, duration);
let mut valid = 0;
let start = Instant::now();
for i in 0..=0x7fff_ffff_u32 {
let cell = 0x0880_0000_001f_ffff | (u64::from(i) << 21);
let is_valid = unsafe { h3ron_h3_sys::h3IsValid(cell) != 0 };
valid += is_valid as usize;
}
let duration = start.elapsed();
println!("found {} valid cells in {:?}", valid, duration);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment