Skip to content

Commit 4fdf8a5

Browse files
committed
Add a benchmark test for sccc finding
While a bit primitive, it should get us at least a better number than nothing.
1 parent ffe5288 commit 4fdf8a5

File tree

1 file changed

+46
-0
lines changed
  • compiler/rustc_data_structures/src/graph/scc

1 file changed

+46
-0
lines changed

compiler/rustc_data_structures/src/graph/scc/tests.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
extern crate test;
2+
13
use super::*;
24
use crate::graph::tests::TestGraph;
35

@@ -139,3 +141,47 @@ fn test_find_state_3() {
139141
assert_eq!(sccs.successors(0), &[]);
140142
assert_eq!(sccs.successors(1), &[0]);
141143
}
144+
145+
#[bench]
146+
fn bench_sccc(b: &mut test::Bencher) {
147+
// Like `test_three_sccs` but each state is replaced by a group of
148+
// three or four to have some amount of test data.
149+
/*
150+
0-3
151+
|
152+
v
153+
+->4-6 11-14
154+
| | |
155+
| v |
156+
+--7-10<-+
157+
*/
158+
fn make_3_clique(slice: &mut [(usize, usize)], base: usize) {
159+
slice[0] = (base + 0, base + 1);
160+
slice[1] = (base + 1, base + 2);
161+
slice[2] = (base + 2, base + 0);
162+
}
163+
// Not actually a clique but strongly connected.
164+
fn make_4_clique(slice: &mut [(usize, usize)], base: usize) {
165+
slice[0] = (base + 0, base + 1);
166+
slice[1] = (base + 1, base + 2);
167+
slice[2] = (base + 2, base + 3);
168+
slice[3] = (base + 3, base + 0);
169+
slice[4] = (base + 1, base + 3);
170+
slice[5] = (base + 2, base + 1);
171+
}
172+
173+
let mut graph = [(0, 0); 6 + 3 + 6 + 3 + 4];
174+
make_4_clique(&mut graph[0..6], 0);
175+
make_3_clique(&mut graph[6..9], 4);
176+
make_4_clique(&mut graph[9..15], 7);
177+
make_3_clique(&mut graph[15..18], 11);
178+
graph[18] = (0, 4);
179+
graph[19] = (5, 7);
180+
graph[20] = (11, 10);
181+
graph[21] = (7, 4);
182+
let graph = TestGraph::new(0, &graph[..]);
183+
b.iter(|| {
184+
let sccs: Sccs<_, usize> = Sccs::new(&graph);
185+
assert_eq!(sccs.num_sccs(), 3);
186+
});
187+
}

0 commit comments

Comments
 (0)