417ccc2c9f
N=100 takes too long (~350 seconds) when running with criterion.rs and I don't know how to limit the number of samples taken (100).
31 lines
839 B
Rust
31 lines
839 B
Rust
use criterion::{criterion_group, criterion_main, Criterion};
|
|
use munkres::{solve_assignment, WeightMatrix};
|
|
|
|
fn gen_matrix(n: usize) -> Vec<i32> {
|
|
(0..n * n)
|
|
.map(|i| {
|
|
let row = i / n;
|
|
let col = i % n;
|
|
(row * col) as i32
|
|
})
|
|
.collect()
|
|
}
|
|
|
|
fn criterion_benchmark(c: &mut Criterion) {
|
|
c.bench_function_over_inputs(
|
|
"solve_assignment",
|
|
|b: &mut criterion::Bencher, n: &usize| {
|
|
let n = *n;
|
|
let matrix = gen_matrix(n);
|
|
b.iter(|| {
|
|
let mut weights: WeightMatrix<i32> = WeightMatrix::from_row_vec(n, matrix.clone());
|
|
let _matching = solve_assignment(&mut weights);
|
|
})
|
|
},
|
|
vec![50],
|
|
);
|
|
}
|
|
|
|
criterion_group!(benches, criterion_benchmark);
|
|
criterion_main!(benches);
|