Skip to content

Commit a00039d

Browse files
committed
Example for performance measurement
1 parent 94a86f9 commit a00039d

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ codegen-units = 1
2727
panic = "abort"
2828
opt-level = 3
2929
# for samply
30-
#debug = 1
30+
debug = 1
3131

3232

3333
[dev-dependencies]

examples/convex_hull.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use rand::{Rng, SeedableRng, rngs::StdRng};
2+
use togo::prelude::*;
3+
4+
/// Configurable number of points
5+
const N_POINTS: usize = 10000;
6+
7+
fn main() {
8+
// Use fixed seed for reproducible results
9+
let mut rng = StdRng::seed_from_u64(42);
10+
11+
// Generate random points once with fixed seed
12+
let points: Pointline = (0..N_POINTS)
13+
.map(|_| point(
14+
rng.random::<f64>() * 10000.0,
15+
rng.random::<f64>() * 10000.0,
16+
))
17+
.collect();
18+
19+
// Compute convex hull
20+
let mut hull = Vec::new();
21+
for _ in 0..500 {
22+
hull = pointline_convex_hull(&points);
23+
}
24+
25+
// Use the result to prevent optimization
26+
println!("Hull size: {}", hull.len());
27+
}
28+
/*
29+
samply record cargo run --release --example convex_hull
30+
31+
*/

0 commit comments

Comments
 (0)