Skip to content

Commit

Permalink
fix: switch from divan to criterion because I don't trust the threade…
Browse files Browse the repository at this point in the history
…d benchmarks
  • Loading branch information
denehoffman committed May 21, 2024
1 parent 36236e5 commit 6a67ab1
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 14 deletions.
221 changes: 221 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pyo3 = "0.21.2"
thiserror = "1.0.60"
factorial = "0.4.0"
sphrs = "0.2.2"
divan = "0.1.14"
criterion = "0.5.1"
rand = "0.8.5"

[profile.release]
Expand Down
2 changes: 1 addition & 1 deletion crates/rustitude/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ rustitude-core = { workspace = true }
rustitude-gluex = { workspace = true, optional = true }

[dev-dependencies]
divan = { workspace = true }
rand = { workspace = true }
criterion = { workspace = true }

[[bench]]
name = "kmatrix"
Expand Down
23 changes: 11 additions & 12 deletions crates/rustitude/benches/kmatrix.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
use divan::black_box;
use criterion::{criterion_group, criterion_main, Criterion};
use rustitude::gluex::harmonics::Zlm;
use rustitude::gluex::resonances::{KMatrixA0, KMatrixA2, KMatrixF0, KMatrixF2};
use rustitude::gluex::utils::{Frame, Reflectivity, Wave};
use rustitude::prelude::*;

fn main() {
divan::main();
}

#[divan::bench(threads = [0, 1, 4, 8, 16])]
fn kmatrix(bencher: divan::Bencher) {
pub fn criterion_kmatrix(c: &mut Criterion) {
let dataset = Dataset::from_parquet("benches/data_pol.parquet");
let f0p: AmpOp = amplitude!("f0+", KMatrixF0::new(2));
let f0n: AmpOp = amplitude!("f0-", KMatrixF0::new(2));
Expand Down Expand Up @@ -41,11 +36,15 @@ fn kmatrix(bencher: divan::Bencher) {
model.fix("f0-", "f0_500 im", 0.0);
model.fix("f0-", "f0_980 im", 0.0);
let m = Manager::new(&model, &dataset);
bencher
.with_inputs(|| {
(0..model.get_n_free())
c.bench_function("kmatrix", |b| {
b.iter(|| {
let v = (0..model.get_n_free())
.map(|_| rand::random::<f64>() * 100.0)
.collect::<Vec<_>>()
.collect::<Vec<_>>();
criterion::black_box(m.evaluate(&v))
})
.bench_values(|v| black_box(m.evaluate(&v)));
});
}

criterion_group!(benches, criterion_kmatrix);
criterion_main!(benches);

0 comments on commit 6a67ab1

Please sign in to comment.