Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f9f4750

Browse files
committed
criterion-based benchmarks
1 parent 92e3ca6 commit f9f4750

File tree

3 files changed

+65
-6
lines changed

3 files changed

+65
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ Cargo.lock
44
.idea
55
**/.DS_Store
66
.vscode
7+
flamegraph.svg

Cargo.toml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
[package]
2-
name = "isosurface"
3-
version = "0.0.4"
42
authors = ["Tristam MacDonald <[email protected]>"]
5-
license = "Apache-2.0"
63
description = "Isosurface extraction algorithms"
7-
repository = "https://github.com/swiftcoder/isosurface"
8-
readme = "README.md"
94
edition = "2018"
5+
license = "Apache-2.0"
6+
name = "isosurface"
7+
readme = "README.md"
8+
repository = "https://github.com/swiftcoder/isosurface"
9+
version = "0.0.4"
1010

1111
[dev-dependencies]
12+
cgmath = "^0.17"
13+
criterion = "0.3"
1214
glium = "^0.26"
1315
glium_text_rusttype = "^0.3"
14-
cgmath = "^0.17"
1516

1617
[profile.dev]
1718
opt-level = 2
19+
20+
[profile.release]
21+
opt-level = 3
22+
lto = true
23+
24+
[[bench]]
25+
name = "isosurface"
26+
harness = false

benches/isosurface.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use criterion::{criterion_group, criterion_main, Criterion};
2+
use isosurface::{
3+
linear_hashed_marching_cubes::LinearHashedMarchingCubes, marching_cubes::MarchingCubes,
4+
source::Source,
5+
};
6+
7+
fn torus(x: f32, y: f32, z: f32) -> f32 {
8+
const R1: f32 = 1.0 / 4.0;
9+
const R2: f32 = 1.0 / 10.0;
10+
let q_x = ((x * x + y * y).sqrt()).abs() - R1;
11+
let len = (q_x * q_x + z * z).sqrt();
12+
len - R2
13+
}
14+
15+
pub struct Torus {}
16+
17+
impl Source for Torus {
18+
fn sample(&self, x: f32, y: f32, z: f32) -> f32 {
19+
torus(x - 0.5, y - 0.5, z - 0.5)
20+
}
21+
}
22+
23+
fn marching_cubes() {
24+
let torus = Torus {};
25+
let mut vertices = vec![];
26+
let mut indices = vec![];
27+
28+
let mut marching_cubes = MarchingCubes::new(256);
29+
marching_cubes.extract(&torus, &mut vertices, &mut indices);
30+
}
31+
32+
fn linear_hashed_marching_cubes() {
33+
let torus = Torus {};
34+
let mut vertices = vec![];
35+
let mut indices = vec![];
36+
37+
let mut marching_cubes = LinearHashedMarchingCubes::new(8);
38+
marching_cubes.extract(&torus, &mut vertices, &mut indices);
39+
}
40+
41+
fn marching_cubes_benchmark(c: &mut Criterion) {
42+
c.bench_function("marching cubes", |b| b.iter(|| marching_cubes()));
43+
c.bench_function("linear hashed marching cubes", |b| {
44+
b.iter(|| linear_hashed_marching_cubes())
45+
});
46+
}
47+
48+
criterion_group!(benches, marching_cubes_benchmark);
49+
criterion_main!(benches);

0 commit comments

Comments
 (0)