summaryrefslogtreecommitdiff
path: root/support/texlab/benches/benchmarks/completion.rs
blob: 4653102460a7abf186a19543a5cbb5d78247f684 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
use criterion::criterion_group;
use criterion::{BenchmarkId, Criterion};
use futures::executor::block_on;
use indoc::indoc;
use std::time::Duration;
use texlab::{completion::CompletionProvider, feature::FeatureTester};

fn criterion_benchmark(criterion: &mut Criterion) {
    criterion.bench_with_input(
        BenchmarkId::new("Completion", "LaTeX Word"),
        &LATEX_CODE,
        |b, code| {
            b.iter(|| {
                block_on(async {
                    FeatureTester::new()
                        .file("main.tex", *code)
                        .main("main.tex")
                        .position(0, 0)
                        .test_completion(CompletionProvider::new())
                        .await
                });
            });
        },
    );

    criterion.bench_with_input(
        BenchmarkId::new("Completion", "LaTeX Command (Filtered)"),
        &LATEX_CODE,
        |b, code| {
            b.iter(|| {
                block_on(async {
                    FeatureTester::new()
                        .file("main.tex", *code)
                        .main("main.tex")
                        .position(0, 1)
                        .test_completion(CompletionProvider::new())
                        .await
                });
            });
        },
    );

    criterion.bench_with_input(
        BenchmarkId::new("Completion", "LaTeX Command (Unfiltered)"),
        &LATEX_CODE,
        |b, code| {
            b.iter(|| {
                block_on(async {
                    FeatureTester::new()
                        .file("main.tex", *code)
                        .main("main.tex")
                        .position(30, 1)
                        .test_completion(CompletionProvider::new())
                        .await
                });
            });
        },
    );

    criterion.bench_with_input(
        BenchmarkId::new("Completion", "LaTeX Environment"),
        &LATEX_CODE,
        |b, code| {
            b.iter(|| {
                block_on(async {
                    FeatureTester::new()
                        .file("main.tex", *code)
                        .main("main.tex")
                        .position(9, 9)
                        .test_completion(CompletionProvider::new())
                        .await
                });
            })
        },
    );

    criterion.bench_with_input(
        BenchmarkId::new("Completion", "LaTeX Label"),
        &LATEX_CODE,
        |b, code| {
            b.iter(|| {
                block_on(async {
                    FeatureTester::new()
                        .file("main.tex", *code)
                        .main("main.tex")
                        .position(15, 7)
                        .test_completion(CompletionProvider::new())
                        .await
                });
            })
        },
    );
}

criterion_group! {
    name = benches;
    config = Criterion::default().measurement_time(Duration::from_secs(60));
    targets = criterion_benchmark
}

static LATEX_CODE: &str = indoc!(
    r#"
        \documentclass{article}
        \usepackage{amsmath}
        \usepackage{lipsum}
        \usepackage{geometry}
        \usepackage[utf8]{inputenc}
        \newcommand{\foo}{foo}
        \DeclareMathOperator{\bar}{bar}
        \include{child1}
        \input{child2.tex}
        \begin{document}
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec fermentum lectus placerat, suscipit ligula quis.
        \begin{equation*}\label{eq:foo}
            e^{i \pi} + 1 = 0
        \end{equation*}
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec fermentum lectus placerat, suscipit ligula quis.
        \ref{eq:foo}
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec fermentum lectus placerat, suscipit ligula quis.
        \section{Foo}\label{sec:foo}
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec fermentum lectus placerat, suscipit ligula quis.
        \subsection{Bar}\label{sec:bar}
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec fermentum lectus placerat, suscipit ligula quis.
        \include{foo}
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec fermentum lectus placerat, suscipit ligula quis.
        \input{bar.tex}
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec fermentum lectus placerat, suscipit ligula quis.
        \cite{foo, bar, baz}
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec fermentum lectus placerat, suscipit ligula quis.
        \nocite{*}
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec fermentum lectus placerat, suscipit ligula quis.
        \end{document}
        \
    "#
);