| |
| """ |
| Generate summary statistics across all tasks and architectures |
| """ |
|
|
| import pandas as pd |
| import os |
| from pathlib import Path |
|
|
|
|
| def generate_model_summary(output_dir: Path): |
| """Generate a summary comparing models across all tasks and architectures""" |
|
|
| |
| task_time_df = pd.read_csv(output_dir / "task_time_statistics.csv") |
| task_token_df = pd.read_csv(output_dir / "task_token_statistics.csv") |
|
|
| |
| merged_df = pd.merge( |
| task_time_df, |
| task_token_df, |
| on=["task", "architecture", "model", "count"], |
| suffixes=("_time", "_token"), |
| ) |
|
|
| |
| model_summary = ( |
| merged_df.groupby("model") |
| .agg( |
| { |
| "count": "sum", |
| "mean_time": "mean", |
| "p90_time": "mean", |
| "p99_time": "mean", |
| "cv_time": "mean", |
| "throughput_tasks_per_hour": "mean", |
| "mean_total": "mean", |
| "cv_total": "mean", |
| "mean_input": "mean", |
| "cv_input": "mean", |
| "mean_output": "mean", |
| "cv_output": "mean", |
| "mean_reasoning": "mean", |
| "cv_reasoning": "mean", |
| "mean_result": "mean", |
| "cv_result": "mean", |
| } |
| ) |
| .round(2) |
| ) |
|
|
| |
| model_summary.columns = [ |
| "total_runs", |
| "avg_mean_time_sec", |
| "avg_p90_time_sec", |
| "avg_p99_time_sec", |
| "avg_cv_time_pct", |
| "avg_throughput_tasks_per_hour", |
| "avg_mean_total_tokens", |
| "avg_cv_total_tokens_pct", |
| "avg_input_tokens", |
| "avg_cv_input_pct", |
| "avg_output_tokens", |
| "avg_cv_output_pct", |
| "avg_reasoning_tokens", |
| "avg_cv_reasoning_pct", |
| "avg_result_tokens", |
| "avg_cv_result_pct", |
| ] |
|
|
| |
| model_summary = model_summary.sort_values("avg_mean_time_sec") |
|
|
| |
| model_summary.to_csv(output_dir / "model_summary.csv") |
| print(f"Model summary saved to {output_dir / 'model_summary.csv'}") |
| print("\n" + "=" * 80) |
| print("MODEL PERFORMANCE SUMMARY (sorted by average time)") |
| print("=" * 80) |
| print(model_summary.to_string()) |
|
|
| |
| task_arch_summary = ( |
| merged_df.groupby(["task", "architecture"]) |
| .agg( |
| { |
| "mean_time": ["min", "max", "mean"], |
| "cv_time": "mean", |
| "mean_total": ["min", "max", "mean"], |
| "cv_total": "mean", |
| } |
| ) |
| .round(2) |
| ) |
|
|
| task_arch_summary.columns = [ |
| "time_min", |
| "time_max", |
| "time_mean", |
| "cv_time_pct", |
| "tokens_min", |
| "tokens_max", |
| "tokens_mean", |
| "cv_total_pct", |
| ] |
|
|
| task_arch_summary.to_csv(output_dir / "task_architecture_summary.csv") |
| print( |
| f"\nTask-architecture summary saved to {output_dir / 'task_architecture_summary.csv'}" |
| ) |
| print("\n" + "=" * 80) |
| print("TASK-ARCHITECTURE SUMMARY") |
| print("=" * 80) |
| print(task_arch_summary.to_string()) |
|
|
| |
| arch_summary = ( |
| merged_df.groupby("architecture") |
| .agg( |
| { |
| "count": "sum", |
| "mean_time": "mean", |
| "cv_time": "mean", |
| "throughput_tasks_per_hour": "mean", |
| "mean_total": "mean", |
| "cv_total": "mean", |
| } |
| ) |
| .round(2) |
| ) |
|
|
| arch_summary.columns = [ |
| "total_runs", |
| "avg_time_sec", |
| "avg_cv_time_pct", |
| "avg_throughput_tasks_per_hour", |
| "avg_total_tokens", |
| "avg_cv_total_pct", |
| ] |
| arch_summary.to_csv(output_dir / "architecture_summary.csv") |
| print(f"\nArchitecture summary saved to {output_dir / 'architecture_summary.csv'}") |
| print("\n" + "=" * 80) |
| print("ARCHITECTURE COMPARISON") |
| print("=" * 80) |
| print(arch_summary.to_string()) |
|
|
| |
| print("\n" + "=" * 80) |
| print("BEST PERFORMERS (by mean time)") |
| print("=" * 80) |
| best_performers = merged_df.nsmallest(10, "mean_time")[ |
| ["task", "architecture", "model", "mean_time", "mean_total"] |
| ] |
| print(best_performers.to_string(index=False)) |
|
|
| print("\n" + "=" * 80) |
| print("SLOWEST PERFORMERS (by mean time)") |
| print("=" * 80) |
| worst_performers = merged_df.nlargest(10, "mean_time")[ |
| ["task", "architecture", "model", "mean_time", "mean_total"] |
| ] |
| print(worst_performers.to_string(index=False)) |
|
|
| |
| merged_df["tokens_per_second"] = merged_df["mean_total"] / merged_df["mean_time"] |
|
|
| print("\n" + "=" * 80) |
| print("TOKEN THROUGHPUT (tokens per second)") |
| print("=" * 80) |
| throughput_summary = ( |
| merged_df.groupby("model")["tokens_per_second"] |
| .mean() |
| .round(2) |
| .sort_values(ascending=False) |
| ) |
| print(throughput_summary.to_string()) |
|
|
| throughput_summary.to_csv( |
| output_dir / "token_throughput_by_model.csv", header=["avg_tokens_per_second"] |
| ) |
| print(f"\nToken throughput saved to {output_dir / 'token_throughput_by_model.csv'}") |
|
|
|
|
| def generate_agent_summary(output_dir: Path): |
| """Generate summary statistics for agents""" |
|
|
| |
| agent_time_df = pd.read_csv(output_dir / "agent_time_statistics.csv") |
| agent_token_df = pd.read_csv(output_dir / "agent_token_statistics.csv") |
|
|
| |
| print("\n" + "=" * 80) |
| print("TOP 10 SLOWEST AGENTS (by mean time)") |
| print("=" * 80) |
| slowest_agents = agent_time_df.nlargest(10, "mean_time")[ |
| ["agent", "task", "architecture", "model", "mean_time", "count"] |
| ] |
| print(slowest_agents.to_string(index=False)) |
| slowest_agents.to_csv(output_dir / "top_10_slowest_agents.csv", index=False) |
|
|
| |
| print("\n" + "=" * 80) |
| print("TOP 10 FASTEST AGENTS (by mean time, min 10 samples)") |
| print("=" * 80) |
| fastest_agents = agent_time_df[agent_time_df["count"] >= 10].nsmallest( |
| 10, "mean_time" |
| )[["agent", "task", "architecture", "model", "mean_time", "count"]] |
| print(fastest_agents.to_string(index=False)) |
| fastest_agents.to_csv(output_dir / "top_10_fastest_agents.csv", index=False) |
|
|
| |
| agent_merged = pd.merge( |
| agent_time_df, |
| agent_token_df, |
| on=["task", "architecture", "agent", "model", "count"], |
| suffixes=("_time", "_token"), |
| ) |
|
|
| |
| print("\n" + "=" * 80) |
| print("TOP 10 MOST TOKEN-HUNGRY AGENTS (by mean total tokens)") |
| print("=" * 80) |
| token_hungry = agent_merged.nlargest(10, "mean_total")[ |
| ["agent", "task", "architecture", "model", "mean_total", "mean_time"] |
| ] |
| print(token_hungry.to_string(index=False)) |
| token_hungry.to_csv(output_dir / "top_10_token_hungry_agents.csv", index=False) |
|
|
| |
| agent_merged["tokens_per_second"] = ( |
| agent_merged["mean_total"] / agent_merged["mean_time"] |
| ) |
|
|
| print("\n" + "=" * 80) |
| print("TOP 10 HIGHEST THROUGHPUT AGENTS (tokens/second)") |
| print("=" * 80) |
| high_throughput = agent_merged.nlargest(10, "tokens_per_second")[ |
| [ |
| "agent", |
| "task", |
| "architecture", |
| "model", |
| "tokens_per_second", |
| "mean_time", |
| "mean_total", |
| ] |
| ] |
| print(high_throughput.to_string(index=False)) |
| high_throughput.to_csv( |
| output_dir / "top_10_high_throughput_agents.csv", index=False |
| ) |
|
|
|
|
| if __name__ == "__main__": |
| print("Generating summary statistics...\n") |
|
|
| |
| script_dir = os.path.dirname(os.path.abspath(__file__)) |
| os.chdir(script_dir) |
|
|
| output_dir = Path(script_dir) / "performance_reports" |
| output_dir.mkdir(parents=True, exist_ok=True) |
|
|
| generate_model_summary(output_dir) |
| generate_agent_summary(output_dir) |
|
|
| print("\n" + "=" * 80) |
| print("Summary generation complete!") |
| print("=" * 80) |
|
|