about summary refs log tree commit diff
path: root/compiler/rustc_data_structures/src/graph/scc
diff options
context:
space:
mode:
authorAndreas Molzer <andreas.molzer@gmx.de>2019-05-23 01:00:07 +0200
committerAndreas Molzer <andreas.molzer@gmx.de>2020-10-31 01:05:15 +0100
commit4fdf8a5630a621c44a0928a1e30d881b0e00022b (patch)
tree1b2d349291391963d61a3235e86a8f95353d227c /compiler/rustc_data_structures/src/graph/scc
parentffe52882ed79be67344dd6085559e308241e7f60 (diff)
downloadrust-4fdf8a5630a621c44a0928a1e30d881b0e00022b.tar.gz
rust-4fdf8a5630a621c44a0928a1e30d881b0e00022b.zip
Add a benchmark test for sccc finding
While a bit primitive, it should get us at least a better number than
nothing.
Diffstat (limited to 'compiler/rustc_data_structures/src/graph/scc')
-rw-r--r--compiler/rustc_data_structures/src/graph/scc/tests.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/compiler/rustc_data_structures/src/graph/scc/tests.rs b/compiler/rustc_data_structures/src/graph/scc/tests.rs
index 1d5f46ebab1..6c1e8e09313 100644
--- a/compiler/rustc_data_structures/src/graph/scc/tests.rs
+++ b/compiler/rustc_data_structures/src/graph/scc/tests.rs
@@ -1,3 +1,5 @@
+extern crate test;
+
 use super::*;
 use crate::graph::tests::TestGraph;
 
@@ -139,3 +141,47 @@ fn test_find_state_3() {
     assert_eq!(sccs.successors(0), &[]);
     assert_eq!(sccs.successors(1), &[0]);
 }
+
+#[bench]
+fn bench_sccc(b: &mut test::Bencher) {
+    // Like `test_three_sccs` but each state is replaced by a group of
+    // three or four to have some amount of test data.
+    /*
+       0-3
+        |
+        v
+    +->4-6 11-14
+    |   |    |
+    |   v    |
+    +--7-10<-+
+         */
+    fn make_3_clique(slice: &mut [(usize, usize)], base: usize) {
+        slice[0] = (base + 0, base + 1);
+        slice[1] = (base + 1, base + 2);
+        slice[2] = (base + 2, base + 0);
+    }
+    // Not actually a clique but strongly connected.
+    fn make_4_clique(slice: &mut [(usize, usize)], base: usize) {
+        slice[0] = (base + 0, base + 1);
+        slice[1] = (base + 1, base + 2);
+        slice[2] = (base + 2, base + 3);
+        slice[3] = (base + 3, base + 0);
+        slice[4] = (base + 1, base + 3);
+        slice[5] = (base + 2, base + 1);
+    }
+
+    let mut graph = [(0, 0); 6 + 3 + 6 + 3 + 4];
+    make_4_clique(&mut graph[0..6], 0);
+    make_3_clique(&mut graph[6..9], 4);
+    make_4_clique(&mut graph[9..15], 7);
+    make_3_clique(&mut graph[15..18], 11);
+    graph[18] = (0, 4);
+    graph[19] = (5, 7);
+    graph[20] = (11, 10);
+    graph[21] = (7, 4);
+    let graph = TestGraph::new(0, &graph[..]);
+    b.iter(|| {
+        let sccs: Sccs<_, usize> = Sccs::new(&graph);
+        assert_eq!(sccs.num_sccs(), 3);
+    });
+}