Files
cleveragents-core/benchmarks/config_cli_bench.py
T
brent.edwards ed9bd090b6
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 15s
CI / build (pull_request) Successful in 14s
CI / quality (pull_request) Successful in 16s
CI / typecheck (pull_request) Successful in 29s
CI / security (pull_request) Successful in 30s
CI / integration_tests (pull_request) Successful in 2m28s
CI / unit_tests (pull_request) Successful in 8m19s
CI / docker (pull_request) Successful in 38s
CI / benchmark-regression (pull_request) Successful in 15m52s
CI / coverage (pull_request) Successful in 17m25s
fix(bench): remove unsupported mix_stderr param from CliRunner in config_cli_bench
Typer 0.24.0 CliRunner does not support the mix_stderr keyword
argument.  This caused ASV benchmark discovery to fail with a
TypeError during the CI benchmark-regression job.
2026-02-20 22:19:26 +00:00

115 lines
3.7 KiB
Python

"""ASV benchmarks for Config CLI command throughput.
Measures the performance of:
- Config list (all settings)
- Config list with regex filter
- Config get (single key resolution)
- Config set (write + read roundtrip)
"""
from __future__ import annotations
import importlib
import shutil
import sys
import tempfile
from pathlib import Path
from unittest.mock import patch
# 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)
import cleveragents # noqa: E402
importlib.reload(cleveragents)
from typer.testing import CliRunner # noqa: E402
from cleveragents.cli.commands import config as config_mod # noqa: E402
from cleveragents.cli.commands.config import app as config_app # noqa: E402
_runner = CliRunner()
class ConfigCLIListSuite:
"""Benchmark config list throughput."""
def setup(self) -> None:
self._tmpdir = Path(tempfile.mkdtemp())
self._tmppath = self._tmpdir / "config.toml"
self._dir_patch = patch.object(config_mod, "_CONFIG_DIR", self._tmpdir)
self._path_patch = patch.object(config_mod, "_CONFIG_PATH", self._tmppath)
self._dir_patch.start()
self._path_patch.start()
def teardown(self) -> None:
self._dir_patch.stop()
self._path_patch.stop()
shutil.rmtree(str(self._tmpdir), ignore_errors=True)
def time_list_all(self) -> None:
"""Benchmark listing all config settings."""
_runner.invoke(config_app, ["list"])
def time_list_with_filter(self) -> None:
"""Benchmark listing with regex filter."""
_runner.invoke(config_app, ["list", "log.*"])
def time_list_json(self) -> None:
"""Benchmark listing in JSON format."""
_runner.invoke(config_app, ["list", "--format", "json"])
class ConfigCLIGetSuite:
"""Benchmark config get throughput."""
def setup(self) -> None:
self._tmpdir = Path(tempfile.mkdtemp())
self._tmppath = self._tmpdir / "config.toml"
self._dir_patch = patch.object(config_mod, "_CONFIG_DIR", self._tmpdir)
self._path_patch = patch.object(config_mod, "_CONFIG_PATH", self._tmppath)
self._dir_patch.start()
self._path_patch.start()
def teardown(self) -> None:
self._dir_patch.stop()
self._path_patch.stop()
shutil.rmtree(str(self._tmpdir), ignore_errors=True)
def time_get_key(self) -> None:
"""Benchmark getting a single config key."""
_runner.invoke(config_app, ["get", "log_level"])
def time_get_key_json(self) -> None:
"""Benchmark getting a key in JSON format."""
_runner.invoke(config_app, ["get", "log_level", "--format", "json"])
class ConfigCLISetSuite:
"""Benchmark config set throughput."""
def setup(self) -> None:
self._tmpdir = Path(tempfile.mkdtemp())
self._tmppath = self._tmpdir / "config.toml"
self._dir_patch = patch.object(config_mod, "_CONFIG_DIR", self._tmpdir)
self._path_patch = patch.object(config_mod, "_CONFIG_PATH", self._tmppath)
self._dir_patch.start()
self._path_patch.start()
def teardown(self) -> None:
self._dir_patch.stop()
self._path_patch.stop()
shutil.rmtree(str(self._tmpdir), ignore_errors=True)
def time_set_key(self) -> None:
"""Benchmark setting a config value."""
_runner.invoke(config_app, ["set", "log_level", "DEBUG"])
def time_set_get_roundtrip(self) -> None:
"""Benchmark set followed by get."""
_runner.invoke(config_app, ["set", "log_level", "DEBUG"])
_runner.invoke(config_app, ["get", "log_level"])