-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(rust): argpcp: reduce re-allocations of intermediate matrices (#9)
* Add benchmark for Argpcp * Use .resize_mut() rather than view().into() to avoid reallocating internal matrices
- Loading branch information
Showing
3 changed files
with
55 additions
and
4 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,43 @@ | ||
use changepoint::*; | ||
use criterion::*; | ||
use rv::process::gaussian::kernel::{ConstantKernel, RBFKernel, WhiteKernel}; | ||
|
||
fn bench_argpcpd(c: &mut Criterion) { | ||
let raw_data: &str = include_str!("../../resources/TB3MS.csv"); | ||
let data: Vec<f64> = raw_data | ||
.lines() | ||
.skip(1) | ||
.map(|line| line.split_at(11).1.parse().unwrap()) | ||
.collect(); | ||
|
||
let mut group = c.benchmark_group("Argpcp"); | ||
|
||
for nelems in (0..500).step_by(100) { | ||
let subdata: Vec<f64> = data.iter().take(nelems).copied().collect(); | ||
|
||
group.throughput(Throughput::Elements(nelems as u64)); | ||
group.bench_with_input( | ||
BenchmarkId::from_parameter(nelems), | ||
&subdata, | ||
|b, data| { | ||
b.iter(|| { | ||
let constant_kernel = ConstantKernel::new(0.5).unwrap(); | ||
let rbf_kernel = RBFKernel::new(10.0).unwrap(); | ||
let white_kernel = WhiteKernel::new(0.01).unwrap(); | ||
let kernel = constant_kernel * rbf_kernel + white_kernel; | ||
// Create the Argpcp processor | ||
let mut cpd = | ||
Argpcp::new(kernel, 3, 2.0, 1.0, -5.0, 1.0, 1.0); | ||
|
||
// Feed data into change point detector | ||
let _res: Vec<Vec<f64>> = | ||
data.iter().map(|d| cpd.step(d).to_vec()).collect(); | ||
}); | ||
}, | ||
); | ||
} | ||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, bench_argpcpd); | ||
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