| 1 |
""" |
| 2 |
This module benchmarks `PathSpec.match_file()` using ~50 patterns. |
| 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_file(): 50 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_50: list[str], |
| 22 |
): |
| 23 |
spec = PathSpec.from_lines( |
| 24 |
'gitignore', |
| 25 |
cpython_gi_lines_50, |
| 26 |
backend='hyperscan', |
| 27 |
) |
| 28 |
benchmark(run_match, spec, cpython_file_match_end) |
| 29 |
|
| 30 |
|
| 31 |
@pytest.mark.benchmark(group=GROUP) |
| 32 |
def bench_hs_v1_middle( |
| 33 |
benchmark: BenchmarkFixture, |
| 34 |
cpython_file_match_middle: str, |
| 35 |
cpython_gi_lines_50: list[str], |
| 36 |
): |
| 37 |
spec = PathSpec.from_lines( |
| 38 |
'gitignore', |
| 39 |
cpython_gi_lines_50, |
| 40 |
backend='hyperscan', |
| 41 |
) |
| 42 |
benchmark(run_match, spec, cpython_file_match_middle) |
| 43 |
|
| 44 |
|
| 45 |
@pytest.mark.benchmark(group=GROUP) |
| 46 |
def bench_hs_v1_none( |
| 47 |
benchmark: BenchmarkFixture, |
| 48 |
cpython_file_match_none: str, |
| 49 |
cpython_gi_lines_50: list[str], |
| 50 |
): |
| 51 |
spec = PathSpec.from_lines( |
| 52 |
'gitignore', |
| 53 |
cpython_gi_lines_50, |
| 54 |
backend='hyperscan', |
| 55 |
) |
| 56 |
benchmark(run_match, spec, cpython_file_match_none) |
| 57 |
|
| 58 |
|
| 59 |
@pytest.mark.benchmark(group=GROUP) |
| 60 |
def bench_hs_v1_start( |
| 61 |
benchmark: BenchmarkFixture, |
| 62 |
cpython_file_match_start: str, |
| 63 |
cpython_gi_lines_50: list[str], |
| 64 |
): |
| 65 |
spec = PathSpec.from_lines( |
| 66 |
'gitignore', |
| 67 |
cpython_gi_lines_50, |
| 68 |
backend='hyperscan', |
| 69 |
) |
| 70 |
benchmark(run_match, spec, cpython_file_match_start) |
| 71 |
|
| 72 |
|
| 73 |
# Re2 backend. |
| 74 |
|
| 75 |
@pytest.mark.benchmark(group=GROUP) |
| 76 |
def bench_re2_v1_end( |
| 77 |
benchmark: BenchmarkFixture, |
| 78 |
cpython_file_match_end: str, |
| 79 |
cpython_gi_lines_50: list[str], |
| 80 |
): |
| 81 |
spec = PathSpec.from_lines( |
| 82 |
'gitignore', |
| 83 |
cpython_gi_lines_50, |
| 84 |
backend='re2', |
| 85 |
) |
| 86 |
benchmark(run_match, spec, cpython_file_match_end) |
| 87 |
|
| 88 |
|
| 89 |
@pytest.mark.benchmark(group=GROUP) |
| 90 |
def bench_re2_v1_middle( |
| 91 |
benchmark: BenchmarkFixture, |
| 92 |
cpython_file_match_middle: str, |
| 93 |
cpython_gi_lines_50: list[str], |
| 94 |
): |
| 95 |
spec = PathSpec.from_lines( |
| 96 |
'gitignore', |
| 97 |
cpython_gi_lines_50, |
| 98 |
backend='re2', |
| 99 |
) |
| 100 |
benchmark(run_match, spec, cpython_file_match_middle) |
| 101 |
|
| 102 |
|
| 103 |
@pytest.mark.benchmark(group=GROUP) |
| 104 |
def bench_re2_v1_none( |
| 105 |
benchmark: BenchmarkFixture, |
| 106 |
cpython_file_match_none: str, |
| 107 |
cpython_gi_lines_50: list[str], |
| 108 |
): |
| 109 |
spec = PathSpec.from_lines( |
| 110 |
'gitignore', |
| 111 |
cpython_gi_lines_50, |
| 112 |
backend='re2', |
| 113 |
) |
| 114 |
benchmark(run_match, spec, cpython_file_match_none) |
| 115 |
|
| 116 |
|
| 117 |
@pytest.mark.benchmark(group=GROUP) |
| 118 |
def bench_re2_v1_start( |
| 119 |
benchmark: BenchmarkFixture, |
| 120 |
cpython_file_match_start: str, |
| 121 |
cpython_gi_lines_50: list[str], |
| 122 |
): |
| 123 |
spec = PathSpec.from_lines( |
| 124 |
'gitignore', |
| 125 |
cpython_gi_lines_50, |
| 126 |
backend='re2', |
| 127 |
) |
| 128 |
benchmark(run_match, spec, cpython_file_match_start) |
| 129 |
|
| 130 |
|
| 131 |
# Simple backend. |
| 132 |
|
| 133 |
@pytest.mark.benchmark(group=GROUP) |
| 134 |
def bench_sm_v1_end( |
| 135 |
benchmark: BenchmarkFixture, |
| 136 |
cpython_file_match_end: str, |
| 137 |
cpython_gi_lines_50: list[str], |
| 138 |
): |
| 139 |
spec = PathSpec.from_lines( |
| 140 |
'gitignore', |
| 141 |
cpython_gi_lines_50, |
| 142 |
backend='simple', |
| 143 |
) |
| 144 |
benchmark(run_match, spec, cpython_file_match_end) |
| 145 |
|
| 146 |
|
| 147 |
@pytest.mark.benchmark(group=GROUP) |
| 148 |
def bench_sm_v1_middle( |
| 149 |
benchmark: BenchmarkFixture, |
| 150 |
cpython_file_match_middle: str, |
| 151 |
cpython_gi_lines_50: list[str], |
| 152 |
): |
| 153 |
spec = PathSpec.from_lines( |
| 154 |
'gitignore', |
| 155 |
cpython_gi_lines_50, |
| 156 |
backend='simple', |
| 157 |
) |
| 158 |
benchmark(run_match, spec, cpython_file_match_middle) |
| 159 |
|
| 160 |
|
| 161 |
@pytest.mark.benchmark(group=GROUP) |
| 162 |
def bench_sm_v1_none( |
| 163 |
benchmark: BenchmarkFixture, |
| 164 |
cpython_file_match_none: str, |
| 165 |
cpython_gi_lines_50: list[str], |
| 166 |
): |
| 167 |
spec = PathSpec.from_lines( |
| 168 |
'gitignore', |
| 169 |
cpython_gi_lines_50, |
| 170 |
backend='simple', |
| 171 |
) |
| 172 |
benchmark(run_match, spec, cpython_file_match_none) |
| 173 |
|
| 174 |
|
| 175 |
@pytest.mark.benchmark(group=GROUP) |
| 176 |
def bench_sm_v1_start( |
| 177 |
benchmark: BenchmarkFixture, |
| 178 |
cpython_file_match_start: str, |
| 179 |
cpython_gi_lines_50: list[str], |
| 180 |
): |
| 181 |
spec = PathSpec.from_lines( |
| 182 |
'gitignore', |
| 183 |
cpython_gi_lines_50, |
| 184 |
backend='simple', |
| 185 |
) |
| 186 |
benchmark(run_match, spec, cpython_file_match_start) |
| 187 |
|
| 188 |
|
| 189 |
def run_match(spec: PathSpec, file: str): |
| 190 |
_match = spec.match_file(file) |