Skip to content
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

flexpolyline bench #46

Merged
merged 3 commits into from
May 13, 2024
Merged
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ geo-types = "0.7.8"
[dev-dependencies]
rand = "0.8.5"
criterion = "0.5.1"
flexpolyline = "0.1.0"

[lib]
bench = false
Expand Down
29 changes: 28 additions & 1 deletion benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ fn build_coords() -> Vec<Coord> {
.collect()
}

fn build_flexpolyline(coords: &[Coord], precision: flexpolyline::Precision) -> flexpolyline::Polyline {
let coords = coords.iter().map(|c| (c.x, c.y));
flexpolyline::Polyline::Data2d {
coordinates: coords.collect(),
precision2d: precision,
}
}

#[allow(unused_must_use)]
fn bench_encode(c: &mut Criterion) {
let coords = build_coords();
Expand All @@ -35,12 +43,21 @@ fn bench_encode(c: &mut Criterion) {
black_box(encode_coordinates(coords.iter().copied(), 6).unwrap());
})
});

// This is just to compare us to another popular library. The format isn't identical so we
// don't expet performance to be identical, but it's some kind of touchstone.
// At time of commit, flexpolyline was ~20% slower at encoding than this crate.
c.bench_function("encode 10_000 coordinates at precision 1e-5 (flexpolyline)", |b| {
let pl = build_flexpolyline(&coords, flexpolyline::Precision::Digits5);
b.iter(|| {
black_box(pl.encode().unwrap());
})
});
}

#[allow(unused_must_use)]
fn bench_decode(c: &mut Criterion) {
let coords = build_coords();

c.bench_function("decode 10_000 coordinates at precision 1e-5", |b| {
let encoded = encode_coordinates(coords.iter().copied(), 5).unwrap();
b.iter(|| {
Expand All @@ -54,6 +71,16 @@ fn bench_decode(c: &mut Criterion) {
black_box(decode_polyline(&encoded, 6).unwrap());
})
});

// This is just to compare us to another popular library. The format isn't identical so we
// don't expet performance to be identical, but it's some kind of touchstone.
// At time of commit, flexpolyline was ~12% slower at decoding than this crate.
c.bench_function("decode 10_000 coordinates at precision 1e-5 (flexpolyline)", |b| {
let encoded = build_flexpolyline(&coords, flexpolyline::Precision::Digits5).encode().unwrap();
b.iter(|| {
black_box(flexpolyline::Polyline::decode(&encoded).unwrap());
})
});
}

criterion_group!(benches, bench_encode, bench_decode,);
Expand Down