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