File: markdown-it.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (29 lines) | stat: -rw-r--r-- 958 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use criterion::{criterion_group, criterion_main, Criterion};
use pulldown_cmark::{html, Parser};
use std::fs::{read_dir, read_to_string};

pub fn markdown_it_samples(c: &mut Criterion) {
    let folder = read_dir("./third_party/markdown-it").unwrap();
    for entry in folder {
        let entry = entry.unwrap();

        if entry.metadata().unwrap().is_file() {
            let filename = &entry.file_name().into_string().unwrap();
            if !filename.ends_with(".md") || filename == "README.md" {
                continue;
            }

            let corpus = read_to_string(entry.path()).unwrap();
            let mut result = String::with_capacity(corpus.len() * 3 / 2);

            c.bench_function(filename, |b| {
                b.iter(|| {
                    html::push_html(&mut result, Parser::new(&corpus));
                })
            });
        }
    }
}

criterion_group!(benches, markdown_it_samples);
criterion_main!(benches);