diff --git a/src/lib.rs b/src/lib.rs index df1f475..4ad702d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ #![feature(zero_one)] +#![feature(test)] /// Kuhn-Munkres Algorithm (also called Hungarian algorithm) for solving the /// Assignment Problem. @@ -18,6 +19,9 @@ extern crate bit_vec; +#[cfg(test)] +extern crate test; + use std::ops::{Add, Sub}; use std::num::Zero; use std::cmp; @@ -613,3 +617,18 @@ fn test_solve_random10() { let mut weights: WeightMatrix = WeightMatrix::from_row_vec(10, c); let _matching = solve_assignment(&mut weights); } + +#[bench] +fn bench_solve100(b: &mut test::Bencher) { + const N: usize = 100; + let matrix: Vec = (0..N*N).map(|i| { + let row = i/N; + let col = i%N; + (row * col) as i32 + }).collect(); + + b.iter(|| { + let mut weights: WeightMatrix = WeightMatrix::from_row_vec(N, matrix.clone()); + let _matching = solve_assignment(&mut weights); + }); +}