Debian Codegraph @

benchmarks/bench_gitignore_150p_to_6500f.py

raw
1 """
2 This module benchmarks :class:`.GitIgnoreSpec` using ~150 patterns against ~6.5k
3 files.
4 """
5
6 from functools import (
7 partial)
8
9 import pytest
10 from pytest_benchmark.fixture import (
11 BenchmarkFixture)
12
13 from pathspec import (
14 GitIgnoreSpec)
15 from pathspec._backends.simple.gitignore import (
16 SimpleGiBackend)
17
18 from benchmarks.hyperscan_gitignore_r1 import (
19 HyperscanGiR1BlockClosureBackend,
20 HyperscanGiR1BlockStateBackend,
21 HyperscanGiR1StreamClosureBackend,
22 HyperscanGiR1StreamStateBackend)
23 from benchmarks.hyperscan_gitignore_r2 import (
24 HyperscanGiR2BlockClosureBackend,
25 HyperscanGiR2BlockStateBackend,
26 HyperscanGiR2StreamClosureBackend)
27
28 GROUP = "GitIgnore.match_files(): 150 lines, 6.5k files"
29
30
31 # Hyperscan backend.
32
33 @pytest.mark.benchmark(group=GROUP)
34 def bench_hs_r1_block_closure(
35 benchmark: BenchmarkFixture,
36 cpython_files: set[str],
37 cpython_gi_lines_all: list[str],
38 ):
39 spec = GitIgnoreSpec.from_lines(
40 cpython_gi_lines_all,
41 backend='hyperscan',
42 _test_backend_factory=HyperscanGiR1BlockClosureBackend,
43 )
44 benchmark(run_match, spec, cpython_files)
45
46
47 @pytest.mark.benchmark(group=GROUP)
48 def bench_hs_r1_block_state(
49 benchmark: BenchmarkFixture,
50 cpython_files: set[str],
51 cpython_gi_lines_all: list[str],
52 ):
53 spec = GitIgnoreSpec.from_lines(
54 cpython_gi_lines_all,
55 backend='hyperscan',
56 _test_backend_factory=HyperscanGiR1BlockStateBackend,
57 )
58 benchmark(run_match, spec, cpython_files)
59
60
61 @pytest.mark.benchmark(group=GROUP)
62 def bench_hs_r1_stream_closure(
63 benchmark: BenchmarkFixture,
64 cpython_files: set[str],
65 cpython_gi_lines_all: list[str],
66 ):
67 spec = GitIgnoreSpec.from_lines(
68 cpython_gi_lines_all,
69 backend='hyperscan',
70 _test_backend_factory=HyperscanGiR1StreamClosureBackend,
71 )
72 benchmark(run_match, spec, cpython_files)
73
74
75 # WARNING: This segfaults.
76 # @pytest.mark.benchmark(group=GROUP)
77 # def bench_hs_r1_stream_state(
78 # benchmark: BenchmarkFixture,
79 # cpython_files: set[str],
80 # cpython_gi_lines_all: list[str],
81 # ):
82 # spec = GitIgnoreSpec.from_lines(
83 # cpython_gi_lines_all,
84 # backend='hyperscan',
85 # _test_backend_factory=GiHyperscanStreamStateBackend,
86 # )
87 # benchmark(run_match, spec, cpython_files)
88
89
90 @pytest.mark.benchmark(group=GROUP)
91 def bench_hs_r2_block_closure(
92 benchmark: BenchmarkFixture,
93 cpython_files: set[str],
94 cpython_gi_lines_all: list[str],
95 ):
96 spec = GitIgnoreSpec.from_lines(
97 cpython_gi_lines_all,
98 backend='hyperscan',
99 _test_backend_factory=HyperscanGiR2BlockClosureBackend,
100 )
101 benchmark(run_match, spec, cpython_files)
102
103
104 @pytest.mark.benchmark(group=GROUP)
105 def bench_hs_r2_block_state(
106 benchmark: BenchmarkFixture,
107 cpython_files: set[str],
108 cpython_gi_lines_all: list[str],
109 ):
110 spec = GitIgnoreSpec.from_lines(
111 cpython_gi_lines_all,
112 backend='hyperscan',
113 _test_backend_factory=HyperscanGiR2BlockStateBackend,
114 )
115 benchmark(run_match, spec, cpython_files)
116
117
118 @pytest.mark.benchmark(group=GROUP)
119 def bench_hs_r2_stream_closure(
120 benchmark: BenchmarkFixture,
121 cpython_files: set[str],
122 cpython_gi_lines_all: list[str],
123 ):
124 spec = GitIgnoreSpec.from_lines(
125 cpython_gi_lines_all,
126 backend='hyperscan',
127 _test_backend_factory=HyperscanGiR2StreamClosureBackend,
128 )
129 benchmark(run_match, spec, cpython_files)
130
131
132 @pytest.mark.benchmark(group=GROUP)
133 def bench_hs_v1(
134 benchmark: BenchmarkFixture,
135 cpython_files: set[str],
136 cpython_gi_lines_all: list[str],
137 ):
138 spec = GitIgnoreSpec.from_lines(
139 cpython_gi_lines_all,
140 backend='hyperscan',
141 )
142 benchmark(run_match, spec, cpython_files)
143
144
145 # Re2 backend.
146
147 @pytest.mark.benchmark(group=GROUP)
148 def bench_re2_v1(
149 benchmark: BenchmarkFixture,
150 cpython_files: set[str],
151 cpython_gi_lines_all: list[str],
152 ):
153 spec = GitIgnoreSpec.from_lines(
154 cpython_gi_lines_all,
155 backend='re2',
156 )
157 benchmark(run_match, spec, cpython_files)
158
159
160 # Simple backend.
161
162 @pytest.mark.benchmark(group=GROUP)
163 def bench_sm_filtered(
164 benchmark: BenchmarkFixture,
165 cpython_files: set[str],
166 cpython_gi_lines_all: list[str],
167 ):
168 spec = GitIgnoreSpec.from_lines(
169 cpython_gi_lines_all,
170 backend='simple',
171 _test_backend_factory=partial(SimpleGiBackend, no_reverse=True)
172 )
173 benchmark(run_match, spec, cpython_files)
174
175
176 @pytest.mark.benchmark(group=GROUP)
177 def bench_sm_filtered_reversed(
178 benchmark: BenchmarkFixture,
179 cpython_files: set[str],
180 cpython_gi_lines_all: list[str],
181 ):
182 spec = GitIgnoreSpec.from_lines(
183 cpython_gi_lines_all,
184 backend='simple',
185 )
186 benchmark(run_match, spec, cpython_files)
187
188
189 @pytest.mark.benchmark(group=GROUP)
190 def bench_sm_unfiltered(
191 benchmark: BenchmarkFixture,
192 cpython_files: set[str],
193 cpython_gi_lines_all: list[str],
194 ):
195 spec = GitIgnoreSpec.from_lines(
196 cpython_gi_lines_all,
197 backend='simple',
198 _test_backend_factory=partial(SimpleGiBackend, no_filter=True, no_reverse=True)
199 )
200 benchmark(run_match, spec, cpython_files)
201
202
203 @pytest.mark.benchmark(group=GROUP)
204 def bench_sm_unfiltered_reversed(
205 benchmark: BenchmarkFixture,
206 cpython_files: set[str],
207 cpython_gi_lines_all: list[str],
208 ):
209 spec = GitIgnoreSpec.from_lines(
210 cpython_gi_lines_all,
211 backend='simple',
212 _test_backend_factory=partial(SimpleGiBackend, no_filter=True)
213 )
214 benchmark(run_match, spec, cpython_files)
215
216
217 @pytest.mark.benchmark(group=GROUP)
218 def bench_sm_v1(
219 benchmark: BenchmarkFixture,
220 cpython_files: set[str],
221 cpython_gi_lines_all: list[str],
222 ):
223 spec = GitIgnoreSpec.from_lines(
224 cpython_gi_lines_all,
225 backend='simple',
226 )
227 benchmark(run_match, spec, cpython_files)
228
229
230 def run_match(spec: GitIgnoreSpec, files: set[str]):
231 for _ in spec.match_files(files):
232 pass