File size: 8,386 Bytes
8c10cf2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | #!/usr/bin/env python3
"""
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"""
# Read the task-level statistics
task_time_df = pd.read_csv(output_dir / "task_time_statistics.csv")
task_token_df = pd.read_csv(output_dir / "task_token_statistics.csv")
# Merge time and token data
merged_df = pd.merge(
task_time_df,
task_token_df,
on=["task", "architecture", "model", "count"],
suffixes=("_time", "_token"),
)
# Group by model to get overall statistics
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)
)
# Rename columns for clarity
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",
]
# Sort by average time
model_summary = model_summary.sort_values("avg_mean_time_sec")
# Save to CSV
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())
# Generate task-architecture summary
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())
# Generate architecture comparison
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())
# Generate best/worst performers
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))
# Token efficiency analysis
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"""
# Read agent statistics
agent_time_df = pd.read_csv(output_dir / "agent_time_statistics.csv")
agent_token_df = pd.read_csv(output_dir / "agent_token_statistics.csv")
# Top 10 slowest agents (by mean time)
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)
# Top 10 fastest agents (with at least 10 samples)
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)
# Merge agent data
agent_merged = pd.merge(
agent_time_df,
agent_token_df,
on=["task", "architecture", "agent", "model", "count"],
suffixes=("_time", "_token"),
)
# Top 10 most token-hungry agents
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 efficiency (tokens per second)
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")
# Change to the script directory
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)
|