]>
Commit | Line | Data |
---|---|---|
48663c56 XL |
1 | #[macro_use] |
2 | extern crate criterion; | |
3 | extern crate pulldown_cmark; | |
4 | ||
5 | use criterion::Criterion; | |
416331ca | 6 | use pulldown_cmark::{html, Options, Parser}; |
48663c56 XL |
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: પ પ પ પ પ પ | |
54 | પ પ પ પ પ પ પ પ પ પ પ પ પ પ | |
55 | પ પ પ પ પ પ પ પ પ પ પ પ પ પ | |
56 | પ પ પ પ પ પ પ પ પ પ પ પ પ પ | |
57 | પ પ પ પ પ પ પ પ પ પ પ પ પ પ | |
58 | પ પ પ પ પ પ પ પ પ પ પ પ પ પ | |
59 | પ પ પ પ પ પ પ પ પ પ પ પ પ પ | |
60 | પ પ પ પ પ પ પ પ પ પ પ પ પ પ"; | |
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); |