-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove flaky, unbounded test and move it to a benchmark (#6102)
Closes #6100 (which was a bit unnecessary and more for testing). The benchmark runs quantile estimations of .5, .9, .95, and .99 on a normal distribution.
- Loading branch information
1 parent
bc457a9
commit 78d3f30
Showing
4 changed files
with
49 additions
and
34 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,42 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
//! Benchmarks for the implementation of the P² algorithm with | ||
//! quantile estimation. | ||
// Copyright 2024 Oxide Computer Company | ||
|
||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; | ||
use oximeter_impl::Quantile; | ||
use rand_distr::{Distribution, Normal}; | ||
|
||
/// Emulates baseline code in a Python implementation of the P² | ||
/// algorithm: | ||
/// <https://github.com/rfrenoy/psquare/blob/master/tests/test_psquare.py#L47>. | ||
fn normal_distribution_quantile(size: i32, p: f64) -> f64 { | ||
let mu = 500.; | ||
let sigma = 100.; | ||
let mut q = Quantile::new(p).unwrap(); | ||
let normal = Normal::new(mu, sigma).unwrap(); | ||
for _ in 0..size { | ||
q.append(normal.sample(&mut rand::thread_rng())).unwrap(); | ||
} | ||
q.estimate().unwrap() | ||
} | ||
|
||
fn baseline_benchmark(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("Quantile"); | ||
let size = 1000; | ||
for p in [0.5, 0.9, 0.95, 0.99].iter() { | ||
group.bench_with_input( | ||
BenchmarkId::new("Estimate on Normal Distribution", p), | ||
p, | ||
|b, p| b.iter(|| normal_distribution_quantile(size, *p)), | ||
); | ||
} | ||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, baseline_benchmark); | ||
criterion_main!(benches); |
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