| 1 |
""" |
| 2 |
This module benchmarks :class:`.GitWildMatchPattern` using ~150 patterns against |
| 3 |
~6.5k files. |
| 4 |
""" |
| 5 |
|
| 6 |
import pytest |
| 7 |
from pytest_benchmark.fixture import ( |
| 8 |
BenchmarkFixture) |
| 9 |
|
| 10 |
from pathspec import ( |
| 11 |
GitIgnoreSpec, |
| 12 |
PathSpec) |
| 13 |
|
| 14 |
from benchmarks.gitwildmatch_v1 import ( |
| 15 |
GitWildMatchV1Pattern) |
| 16 |
|
| 17 |
|
| 18 |
GROUP_GITIGNORE = "GitWildMatchPattern: GitIgnore.match_files(): 150 lines, 6.5k files" |
| 19 |
|
| 20 |
GROUP_PATHSPEC = "GitWildMatchPattern: PathSpec.match_files(): 150 lines, 6.5k files" |
| 21 |
|
| 22 |
|
| 23 |
# # Hyperscan backend. |
| 24 |
# |
| 25 |
# @pytest.mark.benchmark(group=GROUP_GITIGNORE) |
| 26 |
# def bench_hs_gitignore_v1( |
| 27 |
# benchmark: BenchmarkFixture, |
| 28 |
# cpython_files: set[str], |
| 29 |
# cpython_gi_lines_all: list[str], |
| 30 |
# ): |
| 31 |
# spec = GitIgnoreSpec.from_lines( |
| 32 |
# lines=cpython_gi_lines_all, |
| 33 |
# pattern_factory=GitWildMatchV1Pattern, |
| 34 |
# backend='hyperscan', |
| 35 |
# ) |
| 36 |
# benchmark(run_match, spec, cpython_files) |
| 37 |
# |
| 38 |
# |
| 39 |
# @pytest.mark.benchmark(group=GROUP_GITIGNORE) |
| 40 |
# def bench_hs_gitignore_v2( |
| 41 |
# benchmark: BenchmarkFixture, |
| 42 |
# cpython_files: set[str], |
| 43 |
# cpython_gi_lines_all: list[str], |
| 44 |
# ): |
| 45 |
# spec = GitIgnoreSpec.from_lines( |
| 46 |
# lines=cpython_gi_lines_all, |
| 47 |
# backend='hyperscan', |
| 48 |
# ) |
| 49 |
# benchmark(run_match, spec, cpython_files) |
| 50 |
# |
| 51 |
# |
| 52 |
# @pytest.mark.benchmark(group=GROUP_PATHSPEC) |
| 53 |
# def bench_hs_pathspec_v1( |
| 54 |
# benchmark: BenchmarkFixture, |
| 55 |
# cpython_files: set[str], |
| 56 |
# cpython_gi_lines_all: list[str], |
| 57 |
# ): |
| 58 |
# spec = PathSpec.from_lines( |
| 59 |
# lines=cpython_gi_lines_all, |
| 60 |
# pattern_factory=GitWildMatchV1Pattern, |
| 61 |
# backend='hyperscan', |
| 62 |
# ) |
| 63 |
# benchmark(run_match, spec, cpython_files) |
| 64 |
# |
| 65 |
# |
| 66 |
# @pytest.mark.benchmark(group=GROUP_PATHSPEC) |
| 67 |
# def bench_hs_pathspec_v2( |
| 68 |
# benchmark: BenchmarkFixture, |
| 69 |
# cpython_files: set[str], |
| 70 |
# cpython_gi_lines_all: list[str], |
| 71 |
# ): |
| 72 |
# spec = PathSpec.from_lines( |
| 73 |
# lines=cpython_gi_lines_all, |
| 74 |
# pattern_factory='gitwildmatch', |
| 75 |
# backend='hyperscan', |
| 76 |
# ) |
| 77 |
# benchmark(run_match, spec, cpython_files) |
| 78 |
# |
| 79 |
# |
| 80 |
# # Re2 backend. |
| 81 |
# |
| 82 |
# @pytest.mark.benchmark(group=GROUP_GITIGNORE) |
| 83 |
# def bench_re2_gitignore_v1( |
| 84 |
# benchmark: BenchmarkFixture, |
| 85 |
# cpython_files: set[str], |
| 86 |
# cpython_gi_lines_all: list[str], |
| 87 |
# ): |
| 88 |
# spec = GitIgnoreSpec.from_lines( |
| 89 |
# lines=cpython_gi_lines_all, |
| 90 |
# pattern_factory=GitWildMatchV1Pattern, |
| 91 |
# backend='re2', |
| 92 |
# ) |
| 93 |
# benchmark(run_match, spec, cpython_files) |
| 94 |
# |
| 95 |
# |
| 96 |
# @pytest.mark.benchmark(group=GROUP_GITIGNORE) |
| 97 |
# def bench_re2_gitignore_v2( |
| 98 |
# benchmark: BenchmarkFixture, |
| 99 |
# cpython_files: set[str], |
| 100 |
# cpython_gi_lines_all: list[str], |
| 101 |
# ): |
| 102 |
# spec = GitIgnoreSpec.from_lines( |
| 103 |
# lines=cpython_gi_lines_all, |
| 104 |
# backend='re2', |
| 105 |
# ) |
| 106 |
# benchmark(run_match, spec, cpython_files) |
| 107 |
# |
| 108 |
# |
| 109 |
# @pytest.mark.benchmark(group=GROUP_PATHSPEC) |
| 110 |
# def bench_re2_pathspec_v1( |
| 111 |
# benchmark: BenchmarkFixture, |
| 112 |
# cpython_files: set[str], |
| 113 |
# cpython_gi_lines_all: list[str], |
| 114 |
# ): |
| 115 |
# spec = PathSpec.from_lines( |
| 116 |
# lines=cpython_gi_lines_all, |
| 117 |
# pattern_factory=GitWildMatchV1Pattern, |
| 118 |
# backend='re2', |
| 119 |
# ) |
| 120 |
# benchmark(run_match, spec, cpython_files) |
| 121 |
# |
| 122 |
# |
| 123 |
# @pytest.mark.benchmark(group=GROUP_PATHSPEC) |
| 124 |
# def bench_re2_pathspec_v2( |
| 125 |
# benchmark: BenchmarkFixture, |
| 126 |
# cpython_files: set[str], |
| 127 |
# cpython_gi_lines_all: list[str], |
| 128 |
# ): |
| 129 |
# spec = PathSpec.from_lines( |
| 130 |
# lines=cpython_gi_lines_all, |
| 131 |
# pattern_factory='gitwildmatch', |
| 132 |
# backend='re2', |
| 133 |
# ) |
| 134 |
# benchmark(run_match, spec, cpython_files) |
| 135 |
|
| 136 |
|
| 137 |
# Simple backend. |
| 138 |
|
| 139 |
@pytest.mark.benchmark(group=GROUP_GITIGNORE) |
| 140 |
def bench_sm_gitignore_v1( |
| 141 |
benchmark: BenchmarkFixture, |
| 142 |
cpython_files: set[str], |
| 143 |
cpython_gi_lines_all: list[str], |
| 144 |
): |
| 145 |
spec = GitIgnoreSpec.from_lines( |
| 146 |
lines=cpython_gi_lines_all, |
| 147 |
pattern_factory=GitWildMatchV1Pattern, |
| 148 |
backend='simple', |
| 149 |
) |
| 150 |
benchmark(run_match, spec, cpython_files) |
| 151 |
|
| 152 |
|
| 153 |
@pytest.mark.benchmark(group=GROUP_GITIGNORE) |
| 154 |
def bench_sm_gitignore_v2( |
| 155 |
benchmark: BenchmarkFixture, |
| 156 |
cpython_files: set[str], |
| 157 |
cpython_gi_lines_all: list[str], |
| 158 |
): |
| 159 |
spec = GitIgnoreSpec.from_lines( |
| 160 |
lines=cpython_gi_lines_all, |
| 161 |
backend='simple', |
| 162 |
) |
| 163 |
benchmark(run_match, spec, cpython_files) |
| 164 |
|
| 165 |
|
| 166 |
@pytest.mark.benchmark(group=GROUP_PATHSPEC) |
| 167 |
def bench_sm_pathspec_v1( |
| 168 |
benchmark: BenchmarkFixture, |
| 169 |
cpython_files: set[str], |
| 170 |
cpython_gi_lines_all: list[str], |
| 171 |
): |
| 172 |
spec = PathSpec.from_lines( |
| 173 |
lines=cpython_gi_lines_all, |
| 174 |
pattern_factory=GitWildMatchV1Pattern, |
| 175 |
backend='simple', |
| 176 |
) |
| 177 |
benchmark(run_match, spec, cpython_files) |
| 178 |
|
| 179 |
|
| 180 |
@pytest.mark.benchmark(group=GROUP_PATHSPEC) |
| 181 |
def bench_sm_pathspec_v2( |
| 182 |
benchmark: BenchmarkFixture, |
| 183 |
cpython_files: set[str], |
| 184 |
cpython_gi_lines_all: list[str], |
| 185 |
): |
| 186 |
spec = PathSpec.from_lines( |
| 187 |
lines=cpython_gi_lines_all, |
| 188 |
pattern_factory='gitwildmatch', |
| 189 |
backend='simple', |
| 190 |
) |
| 191 |
benchmark(run_match, spec, cpython_files) |
| 192 |
|
| 193 |
|
| 194 |
def run_match(spec: GitIgnoreSpec, files: set[str]): |
| 195 |
for _ in spec.match_files(files): |
| 196 |
pass |