Debian Codegraph @

benchmarks/bench_gitignore_match_file_p150.py

raw
1 """
2 This module benchmarks `GitIgnoreSpec.match_file()` using ~150 patterns.
3 """
4
5 import pytest
6 from pytest_benchmark.fixture import (
7 BenchmarkFixture)
8
9 from pathspec import (
10 GitIgnoreSpec)
11
12 GROUP = "GitIgnoreSpec.match_file(): 150 lines, one file"
13
14
15 # Hyperscan backend.
16
17 @pytest.mark.benchmark(group=GROUP)
18 def bench_hs_v1_end(
19 benchmark: BenchmarkFixture,
20 cpython_file_match_end: str,
21 cpython_gi_lines_all: list[str],
22 ):
23 spec = GitIgnoreSpec.from_lines(
24 cpython_gi_lines_all,
25 backend='hyperscan',
26 )
27 benchmark(run_match, spec, cpython_file_match_end)
28
29
30 @pytest.mark.benchmark(group=GROUP)
31 def bench_hs_v1_middle(
32 benchmark: BenchmarkFixture,
33 cpython_file_match_middle: str,
34 cpython_gi_lines_all: list[str],
35 ):
36 spec = GitIgnoreSpec.from_lines(
37 cpython_gi_lines_all,
38 backend='hyperscan',
39 )
40 benchmark(run_match, spec, cpython_file_match_middle)
41
42
43 @pytest.mark.benchmark(group=GROUP)
44 def bench_hs_v1_none(
45 benchmark: BenchmarkFixture,
46 cpython_file_match_none: str,
47 cpython_gi_lines_all: list[str],
48 ):
49 spec = GitIgnoreSpec.from_lines(
50 cpython_gi_lines_all,
51 backend='hyperscan',
52 )
53 benchmark(run_match, spec, cpython_file_match_none)
54
55
56 @pytest.mark.benchmark(group=GROUP)
57 def bench_hs_v1_start(
58 benchmark: BenchmarkFixture,
59 cpython_file_match_start: str,
60 cpython_gi_lines_all: list[str],
61 ):
62 spec = GitIgnoreSpec.from_lines(
63 cpython_gi_lines_all,
64 backend='hyperscan',
65 )
66 benchmark(run_match, spec, cpython_file_match_start)
67
68
69 # Re2 backend.
70
71 @pytest.mark.benchmark(group=GROUP)
72 def bench_re2_v1_end(
73 benchmark: BenchmarkFixture,
74 cpython_file_match_end: str,
75 cpython_gi_lines_all: list[str],
76 ):
77 spec = GitIgnoreSpec.from_lines(
78 cpython_gi_lines_all,
79 backend='re2',
80 )
81 benchmark(run_match, spec, cpython_file_match_end)
82
83
84 @pytest.mark.benchmark(group=GROUP)
85 def bench_re2_v1_middle(
86 benchmark: BenchmarkFixture,
87 cpython_file_match_middle: str,
88 cpython_gi_lines_all: list[str],
89 ):
90 spec = GitIgnoreSpec.from_lines(
91 cpython_gi_lines_all,
92 backend='re2',
93 )
94 benchmark(run_match, spec, cpython_file_match_middle)
95
96
97 @pytest.mark.benchmark(group=GROUP)
98 def bench_re2_v1_none(
99 benchmark: BenchmarkFixture,
100 cpython_file_match_none: str,
101 cpython_gi_lines_all: list[str],
102 ):
103 spec = GitIgnoreSpec.from_lines(
104 cpython_gi_lines_all,
105 backend='re2',
106 )
107 benchmark(run_match, spec, cpython_file_match_none)
108
109
110 @pytest.mark.benchmark(group=GROUP)
111 def bench_re2_v1_start(
112 benchmark: BenchmarkFixture,
113 cpython_file_match_start: str,
114 cpython_gi_lines_all: list[str],
115 ):
116 spec = GitIgnoreSpec.from_lines(
117 cpython_gi_lines_all,
118 backend='re2',
119 )
120 benchmark(run_match, spec, cpython_file_match_start)
121
122
123 # Simple backend.
124
125 @pytest.mark.benchmark(group=GROUP)
126 def bench_sm_v1_end(
127 benchmark: BenchmarkFixture,
128 cpython_file_match_end: str,
129 cpython_gi_lines_all: list[str],
130 ):
131 spec = GitIgnoreSpec.from_lines(
132 cpython_gi_lines_all,
133 backend='simple',
134 )
135 benchmark(run_match, spec, cpython_file_match_end)
136
137
138 @pytest.mark.benchmark(group=GROUP)
139 def bench_sm_v1_middle(
140 benchmark: BenchmarkFixture,
141 cpython_file_match_middle: str,
142 cpython_gi_lines_all: list[str],
143 ):
144 spec = GitIgnoreSpec.from_lines(
145 cpython_gi_lines_all,
146 backend='simple',
147 )
148 benchmark(run_match, spec, cpython_file_match_middle)
149
150
151 @pytest.mark.benchmark(group=GROUP)
152 def bench_sm_v1_none(
153 benchmark: BenchmarkFixture,
154 cpython_file_match_none: str,
155 cpython_gi_lines_all: list[str],
156 ):
157 spec = GitIgnoreSpec.from_lines(
158 cpython_gi_lines_all,
159 backend='simple',
160 )
161 benchmark(run_match, spec, cpython_file_match_none)
162
163
164 @pytest.mark.benchmark(group=GROUP)
165 def bench_sm_v1_start(
166 benchmark: BenchmarkFixture,
167 cpython_file_match_start: str,
168 cpython_gi_lines_all: list[str],
169 ):
170 spec = GitIgnoreSpec.from_lines(
171 cpython_gi_lines_all,
172 backend='simple',
173 )
174 benchmark(run_match, spec, cpython_file_match_start)
175
176
177 def run_match(spec: GitIgnoreSpec, file: str):
178 _match = spec.match_file(file)