]>
git.proxmox.com Git - rustc.git/blob - vendor/pulldown-cmark/benches/html_rendering.rs
2 extern crate criterion
;
3 extern crate pulldown_cmark
;
5 use criterion
::Criterion
;
6 use pulldown_cmark
::{html, Options, Parser}
;
7 use std
::str::from_utf8
;
9 static CRDT_BYTES
: &[u8] = include_bytes
!("../third_party/xi-editor/crdt.md");
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
);
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);
25 html
::push_html(&mut buf
, Parser
::new_ext(input
, Options
::empty()));
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);
36 html
::push_html(&mut buf
, events
.clone().into_iter());
40 c
.bench_function("crdt_all_options_parse", |b
| {
41 let input
= from_utf8(CRDT_BYTES
).unwrap();
43 b
.iter(|| Parser
::new_ext(input
, full_opts
).count())
46 c
.bench_function("crdt_parse", |b
| {
47 let input
= from_utf8(CRDT_BYTES
).unwrap();
49 b
.iter(|| Parser
::new_ext(input
, Options
::empty()).count())
52 c
.bench_function("smart_punctuation", |b
| {
53 let input
= r
#"""'This here a real "quote"'
55 And -- if you're interested -- some em-dashes. Wait --- she actually said that?
57 Wow... Becky is so 'mean'!
60 b
.iter(|| Parser
::new_ext(input
, full_opts
).count());
63 c
.bench_function("links_n_emphasis", |b
| {
64 let input
= r
#"""This is a [link](example.com). **Cool!**
66 This is a [link](example.com). **Cool!**
68 This is a [link](example.com). **Cool!**
70 This is a [link](example.com). **Cool!**
73 b
.iter(|| Parser
::new_ext(input
, Options
::empty()).count());
76 c
.bench_function("unescapes", |b
| {
77 let input
= "This is by far my favourite unicode code point: પ પ પ પ પ પ
78 પ પ પ પ પ પ પ પ પ પ પ પ પ પ
79 પ પ પ પ પ પ પ પ પ પ પ પ પ પ
80 પ પ પ પ પ પ પ પ પ પ પ પ પ પ
81 પ પ પ પ પ પ પ પ પ પ પ પ પ પ
82 પ પ પ પ પ પ પ પ પ પ પ પ પ પ
83 પ પ પ પ પ પ પ પ પ પ પ પ પ પ
84 પ પ પ પ પ પ પ પ પ પ પ પ પ પ";
86 b
.iter(|| Parser
::new_ext(input
, Options
::empty()).count());
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>";
96 b
.iter(|| Parser
::new_ext(input
, Options
::empty()).count());
100 criterion_group
!(benches
, criterion_benchmark
);
101 criterion_main
!(benches
);