Files
cleveragents-core/benchmarks/resource_cli_bench.py
T
Jeffrey Phillips Freeman f7d2f63ab8
CI / lint (pull_request) Successful in 15s
CI / typecheck (pull_request) Successful in 28s
CI / security (pull_request) Successful in 23s
CI / quality (pull_request) Successful in 15s
CI / integration_tests (pull_request) Successful in 5m11s
CI / build (pull_request) Successful in 16s
CI / unit_tests (pull_request) Successful in 14m31s
CI / docker (pull_request) Successful in 40s
CI / coverage (pull_request) Successful in 8m18s
CI / lint (push) Successful in 13s
CI / typecheck (push) Successful in 28s
CI / security (push) Successful in 23s
CI / quality (push) Successful in 16s
CI / integration_tests (push) Successful in 4m58s
CI / build (push) Successful in 15s
CI / unit_tests (push) Successful in 15m30s
CI / coverage (push) Has been cancelled
CI / docker (push) Has been cancelled
feat(cli): add resource commands (core)
2026-02-16 16:46:54 -05:00

104 lines
3.3 KiB
Python

"""ASV benchmarks for Resource CLI command parsing overhead.
Measures the import time and basic construction of resource CLI objects
to track startup overhead.
"""
from __future__ import annotations
class ResourceCliImportBench:
"""Benchmark resource CLI module import time."""
timeout = 30.0
def setup(self) -> None:
"""Pre-warm Python import caches."""
pass
def time_import_resource_module(self) -> None:
"""Measure import time of the resource CLI module."""
import importlib
import cleveragents.cli.commands.resource as mod
importlib.reload(mod)
def time_import_formatting_module(self) -> None:
"""Measure import time of the formatting module."""
import importlib
import cleveragents.cli.formatting as mod
importlib.reload(mod)
class ResourceDictConversionBench:
"""Benchmark resource dict conversion helpers."""
timeout = 30.0
def setup(self) -> None:
"""Set up test data."""
from datetime import UTC, datetime
self.mock_resource_data = {
"resource_id": "01HXYZ1234567890ABCDEFGHIJ",
"name": "local/bench-resource",
"resource_type_name": "git-checkout",
"classification": "physical",
"description": "Benchmark test resource",
"location": "/tmp/bench",
"properties": {"path": "/tmp/bench", "branch": "main"},
"created_at": datetime.now(tz=UTC),
"updated_at": datetime.now(tz=UTC),
}
def time_resource_dict_construction(self) -> None:
"""Measure dict construction for resource output."""
data = self.mock_resource_data
result = {
"resource_id": data["resource_id"],
"name": data["name"],
"type": data["resource_type_name"],
"classification": str(data["classification"]),
"description": data["description"],
"location": data["location"],
"properties": data["properties"],
"created_at": data["created_at"].isoformat(),
"updated_at": data["updated_at"].isoformat(),
}
assert result["name"] == "local/bench-resource"
class ResourceTypeListBench:
"""Benchmark resource type list operations."""
timeout = 60.0
def setup(self) -> None:
"""Create an in-memory registry with bootstrapped types."""
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from cleveragents.application.services.resource_registry_service import (
ResourceRegistryService,
)
from cleveragents.infrastructure.database.models import Base
engine = create_engine("sqlite:///:memory:", echo=False)
Base.metadata.create_all(engine)
factory = sessionmaker(bind=engine, expire_on_commit=False)
self.service = ResourceRegistryService(session_factory=factory)
self.service.bootstrap_builtin_types()
def time_list_types(self) -> None:
"""Measure listing all resource types."""
types = self.service.list_types()
assert len(types) >= 2
def time_show_type(self) -> None:
"""Measure showing a single resource type."""
spec = self.service.show_type("git-checkout")
assert spec.name == "git-checkout"