summaryrefslogtreecommitdiff
path: root/support/texlab/crates/texlab/benches/bench_main.rs
blob: 7fc6d8fc95ec417d91d930def38aa33dd05c3b08 (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use base_db::{util::LineCol, Owner, Workspace};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use distro::Language;
use lsp_types::{ClientCapabilities, Position, Url};
use parser::{parse_latex, SyntaxConfig};

const CODE: &str = include_str!("../../../texlab.tex");

fn criterion_benchmark(c: &mut Criterion) {
    let config = SyntaxConfig::default();
    c.bench_function("LaTeX/Parser", |b| {
        b.iter(|| parse_latex(black_box(CODE), &config));
    });

    c.bench_function("LaTeX/Completion/Command", |b| {
        let uri = Url::parse("http://example.com/texlab.tex").unwrap();
        let text = CODE.to_string();
        let mut workspace = Workspace::default();
        workspace.open(
            uri.clone(),
            text,
            Language::Tex,
            Owner::Client,
            LineCol { line: 0, col: 0 },
        );

        let client_capabilities = ClientCapabilities::default();

        b.iter(|| {
            texlab::features::completion::complete(
                &workspace,
                &uri,
                Position::new(0, 1),
                &client_capabilities,
                None,
            )
        });
    });

    c.bench_function("BibTeX/Cite", |b| {
        let uri1 = Url::parse("http://example.com/texlab.tex").unwrap();
        let uri2 = Url::parse("http://example.com/rht.bib").unwrap();
        let text1 = r#"\cite{a}\addbibresource{rht.bib}"#.to_string();
        let text2 = include_str!("/home/paddy/texlab-testing/rht.bib").to_string();
        let mut workspace = Workspace::default();
        workspace.open(
            uri1.clone(),
            text1,
            Language::Tex,
            Owner::Client,
            LineCol { line: 0, col: 0 },
        );

        workspace.open(
            uri2.clone(),
            text2,
            Language::Bib,
            Owner::Client,
            LineCol { line: 0, col: 6 },
        );

        let client_capabilities = ClientCapabilities::default();

        b.iter(|| {
            texlab::features::completion::complete(
                &workspace,
                &uri1,
                Position::new(0, 7),
                &client_capabilities,
                None,
            )
        });
    });
}

criterion_group!(benches, criterion_benchmark);

criterion_main!(benches);