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