| 1 |
""" |
| 2 |
This module benchmarks `PathSpec.match_files()` using 150 pattern. |
| 3 |
""" |
| 4 |
|
| 5 |
import pytest |
| 6 |
from pytest_benchmark.fixture import ( |
| 7 |
BenchmarkFixture) |
| 8 |
|
| 9 |
from pathspec import ( |
| 10 |
PathSpec) |
| 11 |
|
| 12 |
GROUP = "PathSpec.match_files(): 150 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: set[str], |
| 21 |
cpython_gi_lines_all: list[str], |
| 22 |
): |
| 23 |
spec = PathSpec.from_lines( |
| 24 |
'gitignore', |
| 25 |
cpython_gi_lines_all, |
| 26 |
backend='hyperscan', |
| 27 |
) |
| 28 |
benchmark(run_match, spec, cpython_files) |
| 29 |
|
| 30 |
|
| 31 |
# Re2 backend. |
| 32 |
|
| 33 |
@pytest.mark.benchmark(group=GROUP) |
| 34 |
def bench_re2_v1( |
| 35 |
benchmark: BenchmarkFixture, |
| 36 |
cpython_files: set[str], |
| 37 |
cpython_gi_lines_all: list[str], |
| 38 |
): |
| 39 |
spec = PathSpec.from_lines( |
| 40 |
'gitignore', |
| 41 |
cpython_gi_lines_all, |
| 42 |
backend='re2', |
| 43 |
) |
| 44 |
benchmark(run_match, spec, cpython_files) |
| 45 |
|
| 46 |
|
| 47 |
# Simple backend. |
| 48 |
|
| 49 |
@pytest.mark.benchmark(group=GROUP) |
| 50 |
def bench_sm_v1( |
| 51 |
benchmark: BenchmarkFixture, |
| 52 |
cpython_files: set[str], |
| 53 |
cpython_gi_lines_all: list[str], |
| 54 |
): |
| 55 |
spec = PathSpec.from_lines( |
| 56 |
'gitignore', |
| 57 |
cpython_gi_lines_all, |
| 58 |
backend='simple', |
| 59 |
) |
| 60 |
benchmark(run_match, spec, cpython_files) |
| 61 |
|
| 62 |
|
| 63 |
def run_match(spec: PathSpec, files: set[str]): |
| 64 |
for _ in spec.match_files(files): |
| 65 |
pass |