summaryrefslogtreecommitdiffstats
path: root/vendor/petgraph/benches/stable_graph.rs
blob: 9dffd91cf43bd22e4c443943e3c86504c2d75aea (plain)
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
79
80
81
82
83
84
85
#![feature(test)]

extern crate petgraph;
extern crate test;

use petgraph::prelude::*;
use test::Bencher;

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

use petgraph::stable_graph::node_index;

#[bench]
fn full_edges_default(bench: &mut Bencher) {
    let a = stable_digraph().full_a();
    bench.iter(|| a.edges(node_index(1)).count())
}

#[bench]
fn full_edges_out(bench: &mut Bencher) {
    let a = stable_digraph().full_a();
    bench.iter(|| a.edges_directed(node_index(1), Outgoing).count())
}

#[bench]
fn full_edges_in(bench: &mut Bencher) {
    let a = stable_digraph().full_a();
    bench.iter(|| a.edges_directed(node_index(1), Incoming).count())
}

#[bench]
fn neighbors_default(bench: &mut Bencher) {
    let a = stable_digraph().full_a();
    bench.iter(|| a.neighbors(node_index(1)).count())
}

#[bench]
fn neighbors_out(bench: &mut Bencher) {
    let a = stable_digraph().full_a();
    bench.iter(|| a.neighbors_directed(node_index(1), Outgoing).count())
}

#[bench]
fn neighbors_in(bench: &mut Bencher) {
    let a = stable_digraph().full_a();
    bench.iter(|| a.neighbors_directed(node_index(1), Incoming).count())
}

#[bench]
fn sccs_stable_graph(bench: &mut Bencher) {
    let a = stable_digraph().bigger();
    bench.iter(|| petgraph::algo::kosaraju_scc(&a));
}

#[bench]
fn sccs_graph(bench: &mut Bencher) {
    let a = digraph().bigger();
    bench.iter(|| petgraph::algo::kosaraju_scc(&a));
}

#[bench]
fn stable_graph_map(bench: &mut Bencher) {
    let a = stable_digraph().bigger();
    bench.iter(|| a.map(|i, _| i, |i, _| i));
}

#[bench]
fn graph_map(bench: &mut Bencher) {
    let a = digraph().bigger();
    bench.iter(|| a.map(|i, _| i, |i, _| i));
}

#[bench]
fn stable_graph_retain_nodes(bench: &mut Bencher) {
    let mut a = stable_digraph().bigger();
    bench.iter(|| a.retain_nodes(|_gr, i| (i.index() + 1) % 3700 != 0));
}

#[bench]
fn stable_graph_retain_edges(bench: &mut Bencher) {
    let mut a = stable_digraph().bigger();
    bench.iter(|| a.retain_edges(|_gr, i| (i.index() + 1) % 3700 != 0));
}