d990fc1b41
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 15s
CI / build (pull_request) Successful in 16s
CI / quality (pull_request) Successful in 19s
CI / typecheck (pull_request) Successful in 37s
CI / security (pull_request) Successful in 37s
CI / unit_tests (pull_request) Successful in 2m30s
CI / integration_tests (pull_request) Successful in 2m57s
CI / docker (pull_request) Successful in 38s
CI / coverage (pull_request) Successful in 4m22s
CI / lint (push) Successful in 12s
CI / build (push) Successful in 15s
CI / quality (push) Successful in 16s
CI / security (push) Successful in 33s
CI / typecheck (push) Successful in 33s
CI / benchmark-regression (push) Has been skipped
CI / unit_tests (push) Successful in 2m8s
CI / docker (push) Successful in 39s
CI / integration_tests (push) Successful in 3m9s
CI / coverage (push) Successful in 4m35s
CI / benchmark-publish (push) Successful in 15m41s
CI / benchmark-regression (pull_request) Successful in 28m58s
Implemented the analyzer plugin framework with AnalyzerProtocol, AnalyzerRegistry for registration/discovery by file extension, PythonAnalyzer (AST-based extraction of modules, classes, functions, imports, docstrings), and MarkdownAnalyzer (section, code block, and link extraction). Both analyzers produce well-formed UKO triples with proper URI schemes. ISSUES CLOSED: #551
158 lines
4.5 KiB
Python
158 lines
4.5 KiB
Python
"""ASV benchmarks for UKO Analyzer Plugin Framework.
|
|
|
|
Measures the performance of:
|
|
- UKOTriple construction overhead
|
|
- AnalyzerRegistry registration and lookup
|
|
- PythonAnalyzer.analyze() on various source sizes
|
|
- MarkdownAnalyzer.analyze() on various document sizes
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# Ensure the local *source* tree is importable even when ASV has an
|
|
# older build of the package installed.
|
|
_SRC = str(Path(__file__).resolve().parents[1] / "src")
|
|
if _SRC not in sys.path:
|
|
sys.path.insert(0, _SRC)
|
|
|
|
# Force-reload so ASV picks up the source tree version.
|
|
import cleveragents # noqa: E402
|
|
|
|
importlib.reload(cleveragents)
|
|
|
|
from cleveragents.domain.models.acms.analyzers import ( # noqa: E402
|
|
AnalyzerRegistry,
|
|
UKOTriple,
|
|
)
|
|
from cleveragents.domain.models.acms.markdown_analyzer import ( # noqa: E402
|
|
MarkdownAnalyzer,
|
|
)
|
|
from cleveragents.domain.models.acms.python_analyzer import ( # noqa: E402
|
|
PythonAnalyzer,
|
|
)
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Sample content
|
|
# ---------------------------------------------------------------------------
|
|
|
|
_SMALL_PYTHON = 'import os\n\ndef hello():\n """Say hello."""\n pass\n'
|
|
|
|
_MEDIUM_PYTHON = (
|
|
'"""Module docstring."""\n\nimport os\nfrom pathlib import Path\n\n'
|
|
+ "\n\n".join(
|
|
f'class Cls{i}:\n """Class {i}."""\n'
|
|
f" def method_{i}(self):\n"
|
|
f' """Method {i}."""\n pass\n'
|
|
for i in range(20)
|
|
)
|
|
)
|
|
|
|
_SMALL_MARKDOWN = "# Hello\n\nWorld\n"
|
|
|
|
_MEDIUM_MARKDOWN = "# Document\n\n" + "\n".join(
|
|
f"## Section {i}\n\nParagraph text for section {i}.\n\n"
|
|
f"```python\nprint({i})\n```\n\n"
|
|
f"[Link {i}](https://example.com/{i})\n"
|
|
for i in range(20)
|
|
)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# UKOTriple benchmarks
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
class TripleConstructionSuite:
|
|
"""Benchmark UKOTriple object creation overhead."""
|
|
|
|
timeout = 60
|
|
|
|
def time_create_object_property_triple(self) -> None:
|
|
UKOTriple(
|
|
subject_uri="uko://code/module/foo",
|
|
predicate="rdf:type",
|
|
object_uri="uko-code:Module",
|
|
)
|
|
|
|
def time_create_data_property_triple(self) -> None:
|
|
UKOTriple(
|
|
subject_uri="uko://code/class/Bar",
|
|
predicate="rdfs:label",
|
|
object_value="Bar",
|
|
confidence=0.9,
|
|
)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# AnalyzerRegistry benchmarks
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
class RegistrySuite:
|
|
"""Benchmark AnalyzerRegistry operations."""
|
|
|
|
timeout = 60
|
|
|
|
def setup(self) -> None:
|
|
self.registry = AnalyzerRegistry()
|
|
self.py = PythonAnalyzer()
|
|
self.md = MarkdownAnalyzer()
|
|
self.registry.register(self.py)
|
|
self.registry.register(self.md)
|
|
|
|
def time_lookup_registered_extension(self) -> None:
|
|
self.registry.get_for_extension(".py")
|
|
|
|
def time_lookup_unregistered_extension(self) -> None:
|
|
self.registry.get_for_extension(".rs")
|
|
|
|
def time_list_extensions(self) -> None:
|
|
self.registry.list_extensions()
|
|
|
|
def time_list_analyzers(self) -> None:
|
|
self.registry.list_analyzers()
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# PythonAnalyzer benchmarks
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
class PythonAnalyzerSuite:
|
|
"""Benchmark PythonAnalyzer.analyze() performance."""
|
|
|
|
timeout = 60
|
|
|
|
def setup(self) -> None:
|
|
self.analyzer = PythonAnalyzer()
|
|
|
|
def time_analyze_small_python(self) -> None:
|
|
self.analyzer.analyze(_SMALL_PYTHON, "src/small.py")
|
|
|
|
def time_analyze_medium_python(self) -> None:
|
|
self.analyzer.analyze(_MEDIUM_PYTHON, "src/medium.py")
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# MarkdownAnalyzer benchmarks
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
class MarkdownAnalyzerSuite:
|
|
"""Benchmark MarkdownAnalyzer.analyze() performance."""
|
|
|
|
timeout = 60
|
|
|
|
def setup(self) -> None:
|
|
self.analyzer = MarkdownAnalyzer()
|
|
|
|
def time_analyze_small_markdown(self) -> None:
|
|
self.analyzer.analyze(_SMALL_MARKDOWN, "docs/small.md")
|
|
|
|
def time_analyze_medium_markdown(self) -> None:
|
|
self.analyzer.analyze(_MEDIUM_MARKDOWN, "docs/medium.md")
|