File: load_and_highlight.rs

package info (click to toggle)
rust-syntect 5.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,672 kB
  • sloc: makefile: 2
file content (40 lines) | stat: -rw-r--r-- 1,199 bytes parent folder | download | duplicates (5)
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
30
31
32
33
34
35
36
37
38
39
40
mod highlight_utils;
mod utils;

/// Measures the time it takes to run the whole pipeline:
///  1. Load assets
///  2. Parse
///  3. Highlight
fn run(b: &mut criterion::Bencher, file: &str) {
    let path = utils::get_test_file_path(file);

    b.iter(|| {
        let ss = syntect::parsing::SyntaxSet::load_defaults_nonewlines();
        let ts = syntect::highlighting::ThemeSet::load_defaults();

        let syntax = ss.find_syntax_for_file(path).unwrap().unwrap();
        let s = std::fs::read_to_string(path).unwrap();

        highlight_utils::do_highlight(&s, &ss, syntax, &ts.themes["base16-ocean.dark"]);
    })
}

fn load_and_highlight_benchmark(c: &mut criterion::Criterion) {
    let mut group = c.benchmark_group("load_and_highlight");
    for input in &[
        "highlight_test.erb",
        "InspiredGitHub.tmTheme",
        "Ruby.sublime-syntax",
        "parser.rs"
    ] {
        group.bench_with_input(format!("\"{}\"", input), input, |b, s| run(b, s));
    }
    group.finish();
}

criterion::criterion_group! {
    name = benches;
    config = criterion::Criterion::default().sample_size(50);
    targets = load_and_highlight_benchmark
}
criterion::criterion_main!(benches);