Debian Codegraph @

benchmarks/bench_pathspec_150p_to_6500f.py

raw
1 """
2 This module benchmarks :class:`.PathSpec` 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 PathSpec)
15 from pathspec._backends.simple.pathspec import (
16 SimplePsBackend)
17
18 from benchmarks.hyperscan_pathspec_r1 import (
19 HyperscanPsR1BlockClosureBackend,
20 HyperscanPsR1BlockStateBackend,
21 HyperscanPsR1StreamClosureBackend,
22 HyperscanPsR1StreamStateBackend)
23
24 GROUP = "PathSpec.match_files(): 150 lines, 6.5k files"
25
26
27 # Hyperscan backend.
28
29 @pytest.mark.benchmark(group=GROUP)
30 def bench_hs_r1_block_closure(
31 benchmark: BenchmarkFixture,
32 cpython_files: set[str],
33 cpython_gi_lines_all: list[str],
34 ):
35 spec = PathSpec.from_lines(
36 'gitwildmatch',
37 cpython_gi_lines_all,
38 backend='hyperscan',
39 _test_backend_factory=HyperscanPsR1BlockClosureBackend,
40 )
41 benchmark(run_match, spec, cpython_files)
42
43
44 @pytest.mark.benchmark(group=GROUP)
45 def bench_hs_r1_block_state(
46 benchmark: BenchmarkFixture,
47 cpython_files: set[str],
48 cpython_gi_lines_all: list[str],
49 ):
50 spec = PathSpec.from_lines(
51 'gitwildmatch',
52 cpython_gi_lines_all,
53 backend='hyperscan',
54 _test_backend_factory=HyperscanPsR1BlockStateBackend,
55 )
56 benchmark(run_match, spec, cpython_files)
57
58
59 @pytest.mark.benchmark(group=GROUP)
60 def bench_hs_r1_stream_closure(
61 benchmark: BenchmarkFixture,
62 cpython_files: set[str],
63 cpython_gi_lines_all: list[str],
64 ):
65 spec = PathSpec.from_lines(
66 'gitwildmatch',
67 cpython_gi_lines_all,
68 backend='hyperscan',
69 _test_backend_factory=HyperscanPsR1StreamClosureBackend,
70 )
71 benchmark(run_match, spec, cpython_files)
72
73
74 # WARNING: This segfaults.
75 # @pytest.mark.benchmark(group=GROUP)
76 # def bench_hs_r1_stream_state(
77 # benchmark: BenchmarkFixture,
78 # cpython_files: set[str],
79 # cpython_gi_lines_all: list[str],
80 # ):
81 # spec = PathSpec.from_lines(
82 # 'gitwildmatch',
83 # cpython_gi_lines_all,
84 # backend='hyperscan',
85 # _test_backend_factory=HyperscanPsR1StreamStateBackend,
86 # )
87 # benchmark(run_match, spec, cpython_files)
88
89
90 @pytest.mark.benchmark(group=GROUP)
91 def bench_hs_v1(
92 benchmark: BenchmarkFixture,
93 cpython_files: set[str],
94 cpython_gi_lines_all: list[str],
95 ):
96 spec = PathSpec.from_lines(
97 'gitwildmatch',
98 cpython_gi_lines_all,
99 backend='hyperscan',
100 )
101 benchmark(run_match, spec, cpython_files)
102
103
104 # Re2 backend.
105
106 @pytest.mark.benchmark(group=GROUP)
107 def bench_re2_v1(
108 benchmark: BenchmarkFixture,
109 cpython_files: set[str],
110 cpython_gi_lines_all: list[str],
111 ):
112 spec = PathSpec.from_lines(
113 'gitwildmatch',
114 cpython_gi_lines_all,
115 backend='re2',
116 )
117 benchmark(run_match, spec, cpython_files)
118
119
120 # Simple backend.
121
122 @pytest.mark.benchmark(group=GROUP)
123 def bench_sm_filtered(
124 benchmark: BenchmarkFixture,
125 cpython_files: set[str],
126 cpython_gi_lines_all: list[str],
127 ):
128 spec = PathSpec.from_lines(
129 'gitwildmatch',
130 cpython_gi_lines_all,
131 backend='simple',
132 _test_backend_factory=partial(SimplePsBackend, no_reverse=True)
133 )
134 benchmark(run_match, spec, cpython_files)
135
136
137 @pytest.mark.benchmark(group=GROUP)
138 def bench_sm_filtered_reversed(
139 benchmark: BenchmarkFixture,
140 cpython_files: set[str],
141 cpython_gi_lines_all: list[str],
142 ):
143 spec = PathSpec.from_lines(
144 'gitwildmatch',
145 cpython_gi_lines_all,
146 backend='simple',
147 _test_backend_factory=SimplePsBackend,
148 )
149 benchmark(run_match, spec, cpython_files)
150
151
152 @pytest.mark.benchmark(group=GROUP)
153 def bench_sm_unfiltered(
154 benchmark: BenchmarkFixture,
155 cpython_files: set[str],
156 cpython_gi_lines_all: list[str],
157 ):
158 spec = PathSpec.from_lines(
159 'gitwildmatch',
160 cpython_gi_lines_all,
161 backend='simple',
162 _test_backend_factory=partial(SimplePsBackend, no_filter=True, no_reverse=True)
163 )
164 benchmark(run_match, spec, cpython_files)
165
166
167 @pytest.mark.benchmark(group=GROUP)
168 def bench_sm_unfiltered_reversed(
169 benchmark: BenchmarkFixture,
170 cpython_files: set[str],
171 cpython_gi_lines_all: list[str],
172 ):
173 spec = PathSpec.from_lines(
174 'gitwildmatch',
175 cpython_gi_lines_all,
176 backend='simple',
177 _test_backend_factory=partial(SimplePsBackend, no_filter=True)
178 )
179 benchmark(run_match, spec, cpython_files)
180
181
182 @pytest.mark.benchmark(group=GROUP)
183 def bench_sm_v1(
184 benchmark: BenchmarkFixture,
185 cpython_files: set[str],
186 cpython_gi_lines_all: list[str],
187 ):
188 spec = PathSpec.from_lines(
189 'gitwildmatch',
190 cpython_gi_lines_all,
191 backend='simple',
192 )
193 benchmark(run_match, spec, cpython_files)
194
195
196 def run_match(spec: PathSpec, files: set[str]):
197 for _ in spec.match_files(files):
198 pass