]> git.proxmox.com Git - rustc.git/blob - vendor/pulldown-cmark-0.6.1/benches/html_rendering.rs
New upstream version 1.45.0+dfsg1
[rustc.git] / vendor / pulldown-cmark-0.6.1 / benches / html_rendering.rs
1 #[macro_use]
2 extern crate criterion;
3 extern crate pulldown_cmark;
4
5 use criterion::Criterion;
6 use pulldown_cmark::{html, Options, Parser};
7 use std::str::from_utf8;
8
9 static CRDT_BYTES: &[u8] = include_bytes!("../third_party/xi-editor/crdt.md");
10
11 fn criterion_benchmark(c: &mut Criterion) {
12 c.bench_function("crdt_total", |b| {
13 let input = from_utf8(CRDT_BYTES).unwrap();
14 let mut buf = String::with_capacity(input.len() * 3 / 2);
15
16 b.iter(|| {
17 buf.clear();
18 html::push_html(&mut buf, Parser::new_ext(input, Options::empty()));
19 })
20 });
21
22 c.bench_function("crdt_html", |b| {
23 let input = from_utf8(CRDT_BYTES).unwrap();
24 let events: Vec<_> = Parser::new_ext(input, Options::empty()).collect();
25 let mut buf = String::with_capacity(input.len() * 3 / 2);
26
27 b.iter(|| {
28 buf.clear();
29 html::push_html(&mut buf, events.clone().into_iter());
30 })
31 });
32
33 c.bench_function("crdt_parse", |b| {
34 let input = from_utf8(CRDT_BYTES).unwrap();
35
36 b.iter(|| Parser::new_ext(input, Options::empty()).count())
37 });
38
39 c.bench_function("links_n_emphasis", |b| {
40 let input = r#"""This is a [link](example.com). **Cool!**
41
42 This is a [link](example.com). **Cool!**
43
44 This is a [link](example.com). **Cool!**
45
46 This is a [link](example.com). **Cool!**
47 """#;
48
49 b.iter(|| Parser::new_ext(input, Options::empty()).count());
50 });
51
52 c.bench_function("unescapes", |b| {
53 let input = "This is by far my favourite unicode code point: &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA;
54 &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA;
55 &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA;
56 &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA;
57 &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA;
58 &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA;
59 &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA;
60 &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA;";
61
62 b.iter(|| Parser::new_ext(input, Options::empty()).count());
63 });
64
65 c.bench_function("autolinks_n_html", |b| {
66 let input = "Drop me a line at <john@example.com>. <emph font-weight='BOLD'>Thanks!</emph> <otherinline>
67 Drop me a line at <john@example.com>. <emph font-weight='BOLD'>Thanks!</emph> <otherinline>
68 Drop me a line at <john@example.com>. <emph font-weight='BOLD'>Thanks!</emph> <otherinline>
69 Drop me a line at <john@example.com>. <emph font-weight='BOLD'>Thanks!</emph> <otherinline>
70 Drop me a line at <john@example.com>. <emph font-weight='BOLD'>Thanks!</emph> <otherinline>";
71
72 b.iter(|| Parser::new_ext(input, Options::empty()).count());
73 });
74 }
75
76 criterion_group!(benches, criterion_benchmark);
77 criterion_main!(benches);