File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,3 +16,13 @@ categories = ["web-programming"]
1616[dependencies ]
1717cssparser = " 0"
1818kuchiki = " 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
Original file line number Diff line number Diff line change 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) ;
You can’t perform that action at this time.
0 commit comments