]>
git.proxmox.com Git - rustc.git/blob - vendor/pulldown-cmark-0.6.1/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 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);
18 html
::push_html(&mut buf
, Parser
::new_ext(input
, Options
::empty()));
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);
29 html
::push_html(&mut buf
, events
.clone().into_iter());
33 c
.bench_function("crdt_parse", |b
| {
34 let input
= from_utf8(CRDT_BYTES
).unwrap();
36 b
.iter(|| Parser
::new_ext(input
, Options
::empty()).count())
39 c
.bench_function("links_n_emphasis", |b
| {
40 let input
= r
#"""This is a [link](example.com). **Cool!**
42 This is a [link](example.com). **Cool!**
44 This is a [link](example.com). **Cool!**
46 This is a [link](example.com). **Cool!**
49 b
.iter(|| Parser
::new_ext(input
, Options
::empty()).count());
52 c
.bench_function("unescapes", |b
| {
53 let input
= "This is by far my favourite unicode code point: પ પ પ પ પ પ
54 પ પ પ પ પ પ પ પ પ પ પ પ પ પ
55 પ પ પ પ પ પ પ પ પ પ પ પ પ પ
56 પ પ પ પ પ પ પ પ પ પ પ પ પ પ
57 પ પ પ પ પ પ પ પ પ પ પ પ પ પ
58 પ પ પ પ પ પ પ પ પ પ પ પ પ પ
59 પ પ પ પ પ પ પ પ પ પ પ પ પ પ
60 પ પ પ પ પ પ પ પ પ પ પ પ પ પ";
62 b
.iter(|| Parser
::new_ext(input
, Options
::empty()).count());
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>";
72 b
.iter(|| Parser
::new_ext(input
, Options
::empty()).count());
76 criterion_group
!(benches
, criterion_benchmark
);
77 criterion_main
!(benches
);