Skip to content

Commit

Permalink
Performance improvements (#10)
Browse files Browse the repository at this point in the history
* tuning

* improvement

* bump to 0.3.6
  • Loading branch information
ciscorn authored Apr 12, 2024
1 parent 97503ac commit c782a9a
Show file tree
Hide file tree
Showing 4 changed files with 686 additions and 655 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "earcut"
version = "0.3.5"
version = "0.3.6"
edition = "2021"
description = "A Rust port of the Earcut polygon triangulation library"
authors = ["Taku Fukada <[email protected]>", "MIERUNE Inc. <[email protected]>"]
license = "ISC"
repository = "https://github.com/MIERUNE/earcut-rs"
categories = ["graphics", "science"]
categories = ["graphics", "science", "no-std"]

[dependencies]
num-traits = "0.2"
Expand Down
65 changes: 50 additions & 15 deletions benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ fn bench(c: &mut Criterion) {
let mut earcut = Earcut::new();
let mut triangles = Vec::new();

c.bench_function("water", |b| {
let (data, hole_indices) = load_fixture("water");
c.bench_function("bad-hole", |b| {
let (data, hole_indices) = load_fixture("bad-hole");
b.iter(|| {
earcut.earcut(data.iter().copied(), &hole_indices, &mut triangles);
})
Expand All @@ -49,6 +49,34 @@ fn bench(c: &mut Criterion) {
})
});

c.bench_function("degenerate", |b| {
let (data, hole_indices) = load_fixture("degenerate");
b.iter(|| {
earcut.earcut(data.iter().copied(), &hole_indices, &mut triangles);
})
});

c.bench_function("dude", |b| {
let (data, hole_indices) = load_fixture("dude");
b.iter(|| {
earcut.earcut(data.iter().copied(), &hole_indices, &mut triangles);
})
});

c.bench_function("empty-square", |b| {
let (data, hole_indices) = load_fixture("empty-square");
b.iter(|| {
earcut.earcut(data.iter().copied(), &hole_indices, &mut triangles);
})
});

c.bench_function("water", |b| {
let (data, hole_indices) = load_fixture("water");
b.iter(|| {
earcut.earcut(data.iter().copied(), &hole_indices, &mut triangles);
})
});

c.bench_function("water2", |b| {
let (data, hole_indices) = load_fixture("water2");
b.iter(|| {
Expand All @@ -70,34 +98,41 @@ fn bench(c: &mut Criterion) {
})
});

c.bench_function("water-huge", |b| {
let (data, hole_indices) = load_fixture("water-huge");
c.bench_function("water4", |b| {
let (data, hole_indices) = load_fixture("water4");
b.iter(|| {
earcut.earcut(data.iter().copied(), &hole_indices, &mut triangles);
assert_eq!(triangles.len(), 5177 * 3)
})
});

c.bench_function("water-huge2", |b| {
let (data, hole_indices) = load_fixture("water-huge2");
c.bench_function("water-huge", |b| {
let (data, hole_indices) = load_fixture("water-huge");
b.iter(|| {
earcut.earcut(data.iter().copied(), &hole_indices, &mut triangles);
assert_eq!(triangles.len(), 5177 * 3)
})
});

c.bench_function("rain", |b| {
let (data, hole_indices) = load_fixture("rain");
c.bench_function("water-huge2", |b| {
let (data, hole_indices) = load_fixture("water-huge2");
b.iter(|| {
earcut.earcut(data.iter().copied(), &hole_indices, &mut triangles);
})
});

c.bench_function("hilbert", |b| {
let (data, hole_indices) = load_fixture("hilbert");
b.iter(|| {
earcut.earcut(data.iter().copied(), &hole_indices, &mut triangles);
})
});
// c.bench_function("rain", |b| {
// let (data, hole_indices) = load_fixture("rain");
// b.iter(|| {
// earcut.earcut(data.iter().copied(), &hole_indices, &mut triangles);
// })
// });

// c.bench_function("hilbert", |b| {
// let (data, hole_indices) = load_fixture("hilbert");
// b.iter(|| {
// earcut.earcut(data.iter().copied(), &hole_indices, &mut triangles);
// })
// });
}

criterion_group!(benches, bench);
Expand Down
2 changes: 1 addition & 1 deletion examples/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn load_fixture(name: &str, num_triangles: usize, expected_deviation: f64) {
}

// check
assert!(triangles.len() == num_triangles);
assert!(triangles.len() == num_triangles * 3);
if !triangles.is_empty() {
assert!(
deviation(vertices.iter().copied(), &hole_indices, &triangles) <= expected_deviation
Expand Down
Loading

0 comments on commit c782a9a

Please sign in to comment.