]> git.proxmox.com Git - rustc.git/blob - vendor/pulldown-cmark/benches/html_rendering.rs
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / vendor / pulldown-cmark / 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 let mut full_opts = Options::empty();
13 full_opts.insert(Options::ENABLE_TABLES);
14 full_opts.insert(Options::ENABLE_FOOTNOTES);
15 full_opts.insert(Options::ENABLE_STRIKETHROUGH);
16 full_opts.insert(Options::ENABLE_TASKLISTS);
17 full_opts.insert(Options::ENABLE_SMART_PUNCTUATION);
18
19 c.bench_function("crdt_total", |b| {
20 let input = from_utf8(CRDT_BYTES).unwrap();
21 let mut buf = String::with_capacity(input.len() * 3 / 2);
22
23 b.iter(|| {
24 buf.clear();
25 html::push_html(&mut buf, Parser::new_ext(input, Options::empty()));
26 })
27 });
28
29 c.bench_function("crdt_html", |b| {
30 let input = from_utf8(CRDT_BYTES).unwrap();
31 let events: Vec<_> = Parser::new_ext(input, Options::empty()).collect();
32 let mut buf = String::with_capacity(input.len() * 3 / 2);
33
34 b.iter(|| {
35 buf.clear();
36 html::push_html(&mut buf, events.clone().into_iter());
37 })
38 });
39
40 c.bench_function("crdt_all_options_parse", |b| {
41 let input = from_utf8(CRDT_BYTES).unwrap();
42
43 b.iter(|| Parser::new_ext(input, full_opts).count())
44 });
45
46 c.bench_function("crdt_parse", |b| {
47 let input = from_utf8(CRDT_BYTES).unwrap();
48
49 b.iter(|| Parser::new_ext(input, Options::empty()).count())
50 });
51
52 c.bench_function("smart_punctuation", |b| {
53 let input = r#"""'This here a real "quote"'
54
55 And -- if you're interested -- some em-dashes. Wait --- she actually said that?
56
57 Wow... Becky is so 'mean'!
58 """#;
59
60 b.iter(|| Parser::new_ext(input, full_opts).count());
61 });
62
63 c.bench_function("links_n_emphasis", |b| {
64 let input = r#"""This is a [link](example.com). **Cool!**
65
66 This is a [link](example.com). **Cool!**
67
68 This is a [link](example.com). **Cool!**
69
70 This is a [link](example.com). **Cool!**
71 """#;
72
73 b.iter(|| Parser::new_ext(input, Options::empty()).count());
74 });
75
76 c.bench_function("unescapes", |b| {
77 let input = "This is by far my favourite unicode code point: &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA;
78 &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA;
79 &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA;
80 &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA;
81 &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA;
82 &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA;
83 &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA;
84 &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA; &#xAAA;";
85
86 b.iter(|| Parser::new_ext(input, Options::empty()).count());
87 });
88
89 c.bench_function("autolinks_n_html", |b| {
90 let input = "Drop me a line at <john@example.com>. <emph font-weight='BOLD'>Thanks!</emph> <otherinline>
91 Drop me a line at <john@example.com>. <emph font-weight='BOLD'>Thanks!</emph> <otherinline>
92 Drop me a line at <john@example.com>. <emph font-weight='BOLD'>Thanks!</emph> <otherinline>
93 Drop me a line at <john@example.com>. <emph font-weight='BOLD'>Thanks!</emph> <otherinline>
94 Drop me a line at <john@example.com>. <emph font-weight='BOLD'>Thanks!</emph> <otherinline>";
95
96 b.iter(|| Parser::new_ext(input, Options::empty()).count());
97 });
98 }
99
100 criterion_group!(benches, criterion_benchmark);
101 criterion_main!(benches);