Add benchmark

This commit is contained in:
Michael Neumann 2015-10-20 00:48:12 +02:00
parent 36e85fc429
commit 5738c7b969

View File

@ -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<i32> = 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<i32> = (0..N*N).map(|i| {
let row = i/N;
let col = i%N;
(row * col) as i32
}).collect();
b.iter(|| {
let mut weights: WeightMatrix<i32> = WeightMatrix::from_row_vec(N, matrix.clone());
let _matching = solve_assignment(&mut weights);
});
}