]> git.proxmox.com Git - rustc.git/blob - vendor/pulldown-cmark-0.7.2/benches/lib.rs
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / vendor / pulldown-cmark-0.7.2 / benches / lib.rs
1 #![feature(test)]
2
3 extern crate pulldown_cmark;
4 extern crate test;
5
6 mod to_html {
7 use pulldown_cmark::{html, Options, Parser};
8
9 fn render_html(text: &str, opts: Options) -> String {
10 let mut s = String::with_capacity(text.len() * 3 / 2);
11 let p = Parser::new_ext(text, opts);
12 html::push_html(&mut s, p);
13 s
14 }
15
16 #[bench]
17 fn pathological_codeblocks1(b: &mut test::Bencher) {
18 // Note that `buf` grows quadratically with number of
19 // iterations. The point here is that the render time shouldn't
20 // grow faster than that.
21 let mut buf = String::new();
22 for i in 1..1000 {
23 for _ in 0..i {
24 buf.push('`');
25 }
26 buf.push(' ');
27 }
28
29 b.iter(|| render_html(&buf, Options::empty()));
30 }
31
32 #[bench]
33 fn advanced_pathological_codeblocks(b: &mut test::Bencher) {
34 let mut buf = String::new();
35 let mut i = 1;
36 while buf.len() < 1250 {
37 for _ in 0..i {
38 buf.push('`');
39 }
40 buf.push(' ');
41 i += 1;
42 }
43 for _ in 0..buf.len() {
44 buf.push_str("*a* ");
45 }
46
47 b.iter(|| render_html(&buf, Options::empty()));
48 }
49 }