51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
"""Benchmarks for CleverAgents CLI entrypoints."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import contextlib
|
|
import io
|
|
import subprocess
|
|
import sys
|
|
from collections.abc import Sequence
|
|
from pathlib import Path
|
|
|
|
try:
|
|
from cleveragents.cli import main
|
|
except ModuleNotFoundError:
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
|
from cleveragents.cli import main
|
|
|
|
|
|
class TimeSuite:
|
|
"""Measure CLI startup behavior via in-process invocation."""
|
|
|
|
@staticmethod
|
|
def _run(argv: Sequence[str]) -> None:
|
|
buffer = io.StringIO()
|
|
with contextlib.redirect_stdout(buffer):
|
|
main(list(argv))
|
|
|
|
def time_help_invocation(self) -> None:
|
|
"""Benchmark the `agents --help` path (in-process)."""
|
|
self._run(["--help"])
|
|
|
|
def time_version_invocation(self) -> None:
|
|
"""Benchmark the `agents --version` path (in-process)."""
|
|
self._run(["--version"])
|
|
|
|
|
|
class StartupSuite:
|
|
"""Measure CLI startup via installed entrypoint."""
|
|
|
|
@staticmethod
|
|
def _run(args: Sequence[str]) -> None:
|
|
subprocess.run(args, check=True, capture_output=True, text=True)
|
|
|
|
def time_help_entrypoint(self) -> None:
|
|
"""Benchmark `agents --help` using entrypoint."""
|
|
self._run(["agents", "--help"])
|
|
|
|
def time_version_entrypoint(self) -> None:
|
|
"""Benchmark `agents --version` using entrypoint."""
|
|
self._run(["agents", "--version"])
|