Skip to content

Commit 37f8c19

Browse files
committed
perf: Add benchmarks
1 parent bb44040 commit 37f8c19

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,13 @@ categories = ["web-programming"]
1616
[dependencies]
1717
cssparser = "0"
1818
kuchiki = "0.8"
19+
20+
[dev-dependencies]
21+
criterion = ">= 0.1"
22+
23+
[[bench]]
24+
name = "inliner"
25+
harness = false
26+
27+
[profile.release]
28+
debug = true

benches/inliner.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2+
use css_inline::inline;
3+
4+
fn simple(c: &mut Criterion) {
5+
let html = black_box(
6+
r#"<html>
7+
<head>
8+
<title>Test</title>
9+
<style>
10+
h1, h2 { color:blue; }
11+
strong { text-decoration:none }
12+
p { font-size:2px }
13+
p.footer { font-size: 1px}
14+
</style>
15+
</head>
16+
<body>
17+
<h1>Big Text</h1>
18+
<p>
19+
<strong>Solid</strong>
20+
</p>
21+
<p class="footer">Foot notes</p>
22+
</body>
23+
</html>"#,
24+
);
25+
c.bench_function("simple HTML", |b| b.iter(|| inline(html).unwrap()));
26+
}
27+
28+
fn merging(c: &mut Criterion) {
29+
let html = black_box(
30+
r#"<html>
31+
<head>
32+
<title>Test</title>
33+
<style>
34+
h1, h2 { color:blue; }
35+
strong { text-decoration:none }
36+
p { font-size:2px }
37+
p.footer { font-size: 1px}
38+
</style>
39+
</head>
40+
<body>
41+
<h1 style="background-color: black;">Big Text</h1>
42+
<p style="background-color: black;">
43+
<strong style="background-color: black;">Solid</strong>
44+
</p>
45+
<p class="footer" style="background-color: black;">Foot notes</p>
46+
</body>
47+
</html>"#,
48+
);
49+
c.bench_function("merging styles", |b| b.iter(|| inline(html).unwrap()));
50+
}
51+
52+
criterion_group!(benches, simple, merging);
53+
criterion_main!(benches);

0 commit comments

Comments
 (0)