test(actor): add ASV benchmarks for actor examples loading
- Measure file loading throughput for all 5 example YAML files - Benchmark complex hierarchical graph parsing performance
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
"""ASV benchmarks for Actor YAML examples loading throughput.
|
||||
|
||||
Measures the performance of:
|
||||
- Loading example YAML files from disk
|
||||
- Validating real-world actor configurations
|
||||
- Parsing complex hierarchical graphs
|
||||
- End-to-end file-to-schema pipeline throughput
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Ensure the local *source* tree is importable
|
||||
_SRC = str(Path(__file__).resolve().parents[1] / "src")
|
||||
if _SRC not in sys.path:
|
||||
sys.path.insert(0, _SRC)
|
||||
|
||||
# Force-reload the top-level package
|
||||
import cleveragents # noqa: E402
|
||||
|
||||
importlib.reload(cleveragents)
|
||||
|
||||
from cleveragents.actor.schema import ActorConfigSchema # noqa: E402
|
||||
|
||||
# Example file paths relative to project root
|
||||
_EXAMPLES_DIR = Path(__file__).resolve().parents[1] / "examples" / "actors"
|
||||
_SIMPLE_LLM = _EXAMPLES_DIR / "simple_llm.yaml"
|
||||
_LLM_WITH_TOOLS = _EXAMPLES_DIR / "llm_with_tools.yaml"
|
||||
_TOOL_COLLECTION = _EXAMPLES_DIR / "tool_collection.yaml"
|
||||
_SIMPLE_GRAPH = _EXAMPLES_DIR / "simple_graph.yaml"
|
||||
_GRAPH_WORKFLOW = _EXAMPLES_DIR / "graph_workflow.yaml"
|
||||
|
||||
|
||||
class TimeActorExamplesSimpleLLM:
|
||||
"""Benchmark loading simple_llm.yaml example."""
|
||||
|
||||
def time_load_simple_llm(self) -> None:
|
||||
"""Time loading and validating simple_llm.yaml."""
|
||||
ActorConfigSchema.from_yaml_file(str(_SIMPLE_LLM))
|
||||
|
||||
|
||||
class TimeActorExamplesLLMWithTools:
|
||||
"""Benchmark loading llm_with_tools.yaml example."""
|
||||
|
||||
def time_load_llm_with_tools(self) -> None:
|
||||
"""Time loading and validating llm_with_tools.yaml (strategist pattern)."""
|
||||
ActorConfigSchema.from_yaml_file(str(_LLM_WITH_TOOLS))
|
||||
|
||||
|
||||
class TimeActorExamplesToolCollection:
|
||||
"""Benchmark loading tool_collection.yaml example."""
|
||||
|
||||
def time_load_tool_collection(self) -> None:
|
||||
"""Time loading and validating tool_collection.yaml."""
|
||||
ActorConfigSchema.from_yaml_file(str(_TOOL_COLLECTION))
|
||||
|
||||
|
||||
class TimeActorExamplesSimpleGraph:
|
||||
"""Benchmark loading simple_graph.yaml example."""
|
||||
|
||||
def time_load_simple_graph(self) -> None:
|
||||
"""Time loading and validating simple_graph.yaml."""
|
||||
ActorConfigSchema.from_yaml_file(str(_SIMPLE_GRAPH))
|
||||
|
||||
|
||||
class TimeActorExamplesGraphWorkflow:
|
||||
"""Benchmark loading graph_workflow.yaml example."""
|
||||
|
||||
def time_load_graph_workflow(self) -> None:
|
||||
"""Time loading and validating graph_workflow.yaml (hierarchical pattern)."""
|
||||
ActorConfigSchema.from_yaml_file(str(_GRAPH_WORKFLOW))
|
||||
|
||||
|
||||
class TimeActorExamplesAllFiles:
|
||||
"""Benchmark loading all example files sequentially."""
|
||||
|
||||
def time_load_all_examples(self) -> None:
|
||||
"""Time loading all 5 example YAML files in sequence."""
|
||||
ActorConfigSchema.from_yaml_file(str(_SIMPLE_LLM))
|
||||
ActorConfigSchema.from_yaml_file(str(_LLM_WITH_TOOLS))
|
||||
ActorConfigSchema.from_yaml_file(str(_TOOL_COLLECTION))
|
||||
ActorConfigSchema.from_yaml_file(str(_SIMPLE_GRAPH))
|
||||
ActorConfigSchema.from_yaml_file(str(_GRAPH_WORKFLOW))
|
||||
|
||||
|
||||
class TimeActorExamplesReload:
|
||||
"""Benchmark repeated loading of the same file."""
|
||||
|
||||
def time_reload_complex_example(self) -> None:
|
||||
"""Time loading graph_workflow.yaml multiple times (cache behavior)."""
|
||||
for _ in range(5):
|
||||
ActorConfigSchema.from_yaml_file(str(_GRAPH_WORKFLOW))
|
||||
|
||||
|
||||
# Module-level metadata for ASV
|
||||
time_simple_llm = TimeActorExamplesSimpleLLM()
|
||||
time_llm_with_tools = TimeActorExamplesLLMWithTools()
|
||||
time_tool_collection = TimeActorExamplesToolCollection()
|
||||
time_simple_graph = TimeActorExamplesSimpleGraph()
|
||||
time_graph_workflow = TimeActorExamplesGraphWorkflow()
|
||||
time_all_files = TimeActorExamplesAllFiles()
|
||||
time_reload = TimeActorExamplesReload()
|
||||
Reference in New Issue
Block a user