-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
96 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
output/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use std::{env, fs::File}; | ||
|
||
use divan::{bench, black_box, AllocProfiler, Bencher}; | ||
use linear_algebra::{point, Point2}; | ||
use pprof::{ProfilerGuard, ProfilerGuardBuilder}; | ||
use rand::SeedableRng; | ||
use rand_chacha::ChaChaRng; | ||
use ransac::circles::{circle::RansacCircle, test_utilities::generate_circle}; | ||
|
||
#[global_allocator] | ||
static ALLOC: AllocProfiler = AllocProfiler::system(); | ||
|
||
fn main() { | ||
divan::main(); | ||
} | ||
|
||
fn get_profiler_guard() -> Option<ProfilerGuard<'static>> { | ||
if env::var("ENABLE_FLAMEGRAPH").is_ok_and(|v| v == "1") { | ||
ProfilerGuardBuilder::default() | ||
.frequency(1000) | ||
.blocklist(&["pthread", "vdso"]) | ||
.build() | ||
.ok() | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
fn get_flamegraph(file_name: &str, guard: Option<ProfilerGuard<'static>>) { | ||
if let Some(report) = guard.map(|guard| guard.report().build().ok()).flatten() { | ||
let file = File::create(format!( | ||
"{}/benches/output/{}.svg", | ||
env!("CARGO_MANIFEST_DIR"), | ||
file_name | ||
)) | ||
.unwrap(); | ||
report.flamegraph(file).unwrap(); | ||
}; | ||
} | ||
|
||
const TYPICAL_RADIUS: f32 = 0.75; | ||
const GENERATION_VARIATION: f32 = 0.08; | ||
const ACCEPTED_RADIUS_VARIANCE: f32 = 0.1; | ||
const REL_ASSERT_EPSILON: f32 = 1e-5; | ||
const HIGH_POINT_COUNT: usize = 2000; | ||
const HIGH_ITERATIONS: usize = 1500; | ||
const RANDOM_SEED: u64 = 666; | ||
|
||
struct SomeFrame {} | ||
|
||
#[bench(min_time = 30)] | ||
fn noisy_circle(bencher: Bencher) { | ||
let center = point![2.0, 1.5]; | ||
let radius = TYPICAL_RADIUS; | ||
let points: Vec<Point2<SomeFrame>> = generate_circle( | ||
¢er, | ||
HIGH_POINT_COUNT, | ||
radius, | ||
GENERATION_VARIATION, | ||
RANDOM_SEED, | ||
); | ||
let mut rng = ChaChaRng::seed_from_u64(RANDOM_SEED); | ||
|
||
let gen = bencher.with_inputs(|| { | ||
let ransac = RansacCircle::<SomeFrame>::new( | ||
TYPICAL_RADIUS, | ||
ACCEPTED_RADIUS_VARIANCE, | ||
black_box(points.clone()), | ||
); | ||
ransac | ||
}); | ||
let guard = get_profiler_guard(); | ||
gen.bench_local_values(move |mut ransac| { | ||
black_box( | ||
ransac | ||
.next_candidate(black_box(&mut rng), black_box(HIGH_ITERATIONS)) | ||
.expect("No circle was found"), | ||
); | ||
}); | ||
get_flamegraph("ransac_noisy_circle", guard); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
pub mod circle; | ||
mod test_utilities; | ||
pub mod test_utilities; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters