File: matching.rs

package info (click to toggle)
rust-petgraph 0.6.4-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 5,260 kB
  • sloc: makefile: 25
file content (78 lines) | stat: -rw-r--r-- 1,606 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#![feature(test)]

extern crate petgraph;
extern crate test;

use test::Bencher;

#[allow(dead_code)]
mod common;
use common::*;

use petgraph::algo::{greedy_matching, maximum_matching};
use petgraph::graph::UnGraph;

fn huge() -> UnGraph<(), ()> {
    static NODE_COUNT: u32 = 1_000;

    let mut edges = Vec::new();

    for i in 0..NODE_COUNT {
        for j in i..NODE_COUNT {
            if i % 3 == 0 && j % 2 == 0 {
                edges.push((i, j));
            }
        }
    }

    // 999 nodes, 83500 edges
    UnGraph::from_edges(&edges)
}

#[bench]
fn greedy_matching_bipartite(bench: &mut Bencher) {
    let g = ungraph().bipartite();
    bench.iter(|| greedy_matching(&g));
}

#[bench]
fn greedy_matching_full(bench: &mut Bencher) {
    let g = ungraph().full_a();
    bench.iter(|| greedy_matching(&g));
}

#[bench]
fn greedy_matching_bigger(bench: &mut Bencher) {
    let g = ungraph().bigger();
    bench.iter(|| greedy_matching(&g));
}

#[bench]
fn greedy_matching_huge(bench: &mut Bencher) {
    let g = huge();
    bench.iter(|| greedy_matching(&g));
}

#[bench]
fn maximum_matching_bipartite(bench: &mut Bencher) {
    let g = ungraph().bipartite();
    bench.iter(|| maximum_matching(&g));
}

#[bench]
fn maximum_matching_full(bench: &mut Bencher) {
    let g = ungraph().full_a();
    bench.iter(|| maximum_matching(&g));
}

#[bench]
fn maximum_matching_bigger(bench: &mut Bencher) {
    let g = ungraph().bigger();
    bench.iter(|| maximum_matching(&g));
}

#[bench]
fn maximum_matching_huge(bench: &mut Bencher) {
    let g = huge();
    bench.iter(|| maximum_matching(&g));
}