-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathbfs.rs
More file actions
60 lines (50 loc) · 2.02 KB
/
Copy pathbfs.rs
File metadata and controls
60 lines (50 loc) · 2.02 KB
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
use divan::Bencher;
use eurorust_2025_workshop::bfs::{bfs_optimized, generate_graph};
fn main() {
divan::main();
}
#[divan::bench]
fn bfs_small_graph(bencher: Bencher) {
let graph = generate_graph(100);
bencher.bench_local(|| {
let result = divan::black_box(bfs_optimized(divan::black_box(&graph), divan::black_box(0)));
assert!(!result.is_empty(), "BFS result should not be empty");
assert!(
result.len() <= 100,
"BFS result should not exceed graph size"
);
assert_eq!(result[0], 0, "First node should be the start node");
assert_eq!(result[10], 25, "Node at position 10 should be 25");
assert_eq!(result[50], 53, "Node at position 50 should be 53");
});
}
#[divan::bench]
fn bfs_medium_graph(bencher: Bencher) {
let graph = generate_graph(1000);
bencher.bench_local(|| {
let result = divan::black_box(bfs_optimized(divan::black_box(&graph), divan::black_box(0)));
assert!(!result.is_empty(), "BFS result should not be empty");
assert!(
result.len() <= 1000,
"BFS result should not exceed graph size"
);
assert_eq!(result[0], 0, "First node should be the start node");
assert_eq!(result[100], 428, "Node at position 100 should be 428");
assert_eq!(result[500], 397, "Node at position 500 should be 397");
});
}
#[divan::bench]
fn bfs_large_graph(bencher: Bencher) {
let graph = generate_graph(10000);
bencher.bench_local(|| {
let result = divan::black_box(bfs_optimized(divan::black_box(&graph), divan::black_box(0)));
assert!(!result.is_empty(), "BFS result should not be empty");
assert!(
result.len() <= 10000,
"BFS result should not exceed graph size"
);
assert_eq!(result[0], 0, "First node should be the start node");
assert_eq!(result[1000], 7575, "Node at position 1000 should be 7575");
assert_eq!(result[2500], 5949, "Node at position 2500 should be 5949");
});
}