-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaudit.rs
115 lines (94 loc) · 3.61 KB
/
audit.rs
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
use accessibility_rs::{audit, AuditConfig};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
mod mock;
/// bench audit speed
#[cfg(all(not(feature = "tokio"), not(feature = "spider")))]
pub fn bench_speed(c: &mut Criterion) {
let mut group = c.benchmark_group("audit-speed/core");
group.sample_size(50);
group.bench_function(format!("audit: {}", "small html"), |b| {
let conf = AuditConfig::basic(mock::MOCK_WEBSITE_SMALL_HTML);
b.iter(|| black_box(audit(&conf)))
});
group.bench_function(format!("audit: {}", "medium html"), |b| {
let conf = AuditConfig::basic(
mock::MOCK_WEBSITE_A11YWATCH_HTML,
);
b.iter(|| {
black_box(audit(&conf))
})
});
group.bench_function(format!("audit: {}", "medium-large html"), |b| {
let conf = AuditConfig::basic(mock::MOCK_WEBSITE_HTML);
b.iter(|| black_box(audit(&conf)))
});
group.bench_function(format!("audit: {}", "large-xlarge html"), |b| {
let conf = AuditConfig::basic(mock::MOCK_WEBSITE_LARGE_HTML);
b.iter(|| black_box(audit(&conf)))
});
group.finish();
}
/// bench audit speed
#[cfg(all(feature = "tokio", not(feature = "spider")))]
pub fn bench_speed(c: &mut Criterion) {
let mut group = c.benchmark_group("audit-speed/core");
let rt = tokio::runtime::Runtime::new().unwrap();
group.bench_function(format!("audit: {}", "small html"), |b| {
b.to_async(&rt)
.iter(|| black_box(audit(&AuditConfig::basic(mock::MOCK_WEBSITE_SMALL_HTML))))
});
group.bench_function(format!("audit: {}", "medium html"), |b| {
b.to_async(&rt).iter(|| {
black_box(audit(&AuditConfig::basic(
mock::MOCK_WEBSITE_A11YWATCH_HTML,
)))
})
});
group.bench_function(format!("audit: {}", "medium-large html"), |b| {
b.to_async(&rt)
.iter(|| black_box(audit(&AuditConfig::basic(mock::MOCK_WEBSITE_HTML))))
});
group.bench_function(format!("audit: {}", "large-xlarge html"), |b| {
b.to_async(&rt)
.iter(|| black_box(audit(&AuditConfig::basic(mock::MOCK_WEBSITE_LARGE_HTML))))
});
group.finish();
}
/// bench audit speed
#[cfg(feature = "spider")]
pub fn bench_speed(c: &mut Criterion) {
let mut group = c.benchmark_group("audit-speed/core");
let rt = accessibility_rs::spider::tokio::runtime::Runtime::new().unwrap();
group.bench_function(format!("audit: {}", "small html"), |b| {
b.to_async(&rt)
.iter(|| black_box(audit(&AuditConfig::basic(mock::MOCK_WEBSITE_SMALL_HTML))))
});
group.bench_function(format!("audit: {}", "medium html"), |b| {
b.to_async(&rt).iter(|| {
black_box(audit(&AuditConfig::basic(
mock::MOCK_WEBSITE_A11YWATCH_HTML,
)))
})
});
group.bench_function(format!("audit: {}", "medium-large html"), |b| {
b.to_async(&rt)
.iter(|| black_box(audit(&AuditConfig::basic(mock::MOCK_WEBSITE_HTML))))
});
group.bench_function(format!("audit: {}", "large-xlarge html"), |b| {
b.to_async(&rt)
.iter(|| black_box(audit(&AuditConfig::basic(mock::MOCK_WEBSITE_LARGE_HTML))))
});
group.bench_function(format!("audit: {}", "spider audit html"), |b| {
b.to_async(&rt).iter(|| {
black_box(audit(&AuditConfig::new_website(
"https://choosealicense.com",
"",
false,
"",
)))
})
});
group.finish();
}
criterion_group!(benches, bench_speed);
criterion_main!(benches);