Debian Codegraph @

benchmarks/bench_gitignore_match_files_p5.py

raw
1 """
2 This module benchmarks `GitIgnoreSpec.match_files()` using 5 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_files(): 5 lines, 6.5k files"
13
14
15 # Hyperscan backend.
16
17 @pytest.mark.benchmark(group=GROUP)
18 def bench_hs_v1(
19 benchmark: BenchmarkFixture,
20 cpython_files: str,
21 cpython_gi_lines_5: list[str],
22 ):
23 spec = GitIgnoreSpec.from_lines(
24 cpython_gi_lines_5,
25 backend='hyperscan',
26 )
27 benchmark(run_match, spec, cpython_files)
28
29
30 # Re2 backend.
31
32 @pytest.mark.benchmark(group=GROUP)
33 def bench_re2_v1(
34 benchmark: BenchmarkFixture,
35 cpython_files: str,
36 cpython_gi_lines_5: list[str],
37 ):
38 spec = GitIgnoreSpec.from_lines(
39 cpython_gi_lines_5,
40 backend='re2',
41 )
42 benchmark(run_match, spec, cpython_files)
43
44
45 # Simple backend.
46
47 @pytest.mark.benchmark(group=GROUP)
48 def bench_sm_v1(
49 benchmark: BenchmarkFixture,
50 cpython_files: str,
51 cpython_gi_lines_5: list[str],
52 ):
53 spec = GitIgnoreSpec.from_lines(
54 cpython_gi_lines_5,
55 backend='simple',
56 )
57 benchmark(run_match, spec, cpython_files)
58
59
60 def run_match(spec: GitIgnoreSpec, files: set[str]):
61 for _ in spec.match_files(files):
62 pass