-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathbenchmark-agent.sh
More file actions
executable file
·118 lines (100 loc) · 3.03 KB
/
benchmark-agent.sh
File metadata and controls
executable file
·118 lines (100 loc) · 3.03 KB
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
#!/bin/bash
# Benchmark script for comparing direct vs agent mode performance
# Usage: ./benchmark-agent.sh [iterations]
ITERATIONS=${1:-10}
QUERY="what organizations do I have access to?"
echo "=========================================="
echo "MCP Agent Performance Benchmark"
echo "=========================================="
echo "Query: $QUERY"
echo "Iterations: $ITERATIONS"
echo ""
# Arrays to store timings
declare -a direct_times
declare -a agent_times
echo "Running direct mode tests..."
for i in $(seq 1 $ITERATIONS); do
echo -n " Run $i/$ITERATIONS... "
# Run and capture timing (real time in seconds)
START=$(date +%s.%N)
pnpm -w run cli "$QUERY" > /dev/null 2>&1
END=$(date +%s.%N)
# Calculate duration
DURATION=$(echo "$END - $START" | bc)
direct_times+=($DURATION)
echo "${DURATION}s"
done
echo ""
echo "Running agent mode tests..."
for i in $(seq 1 $ITERATIONS); do
echo -n " Run $i/$ITERATIONS... "
# Run and capture timing
START=$(date +%s.%N)
pnpm -w run cli --agent "$QUERY" > /dev/null 2>&1
END=$(date +%s.%N)
# Calculate duration
DURATION=$(echo "$END - $START" | bc)
agent_times+=($DURATION)
echo "${DURATION}s"
done
echo ""
echo "=========================================="
echo "Results"
echo "=========================================="
# Calculate statistics for direct mode
direct_sum=0
direct_min=${direct_times[0]}
direct_max=${direct_times[0]}
for time in "${direct_times[@]}"; do
direct_sum=$(echo "$direct_sum + $time" | bc)
if (( $(echo "$time < $direct_min" | bc -l) )); then
direct_min=$time
fi
if (( $(echo "$time > $direct_max" | bc -l) )); then
direct_max=$time
fi
done
direct_avg=$(echo "scale=2; $direct_sum / $ITERATIONS" | bc)
# Calculate statistics for agent mode
agent_sum=0
agent_min=${agent_times[0]}
agent_max=${agent_times[0]}
for time in "${agent_times[@]}"; do
agent_sum=$(echo "$agent_sum + $time" | bc)
if (( $(echo "$time < $agent_min" | bc -l) )); then
agent_min=$time
fi
if (( $(echo "$time > $agent_max" | bc -l) )); then
agent_max=$time
fi
done
agent_avg=$(echo "scale=2; $agent_sum / $ITERATIONS" | bc)
# Calculate difference
diff=$(echo "scale=2; $agent_avg - $direct_avg" | bc)
percent=$(echo "scale=1; ($agent_avg - $direct_avg) / $direct_avg * 100" | bc)
echo ""
echo "Direct Mode:"
echo " Min: ${direct_min}s"
echo " Max: ${direct_max}s"
echo " Average: ${direct_avg}s"
echo ""
echo "Agent Mode:"
echo " Min: ${agent_min}s"
echo " Max: ${agent_max}s"
echo " Average: ${agent_avg}s"
echo ""
echo "Difference:"
if (( $(echo "$diff > 0" | bc -l) )); then
echo " +${diff}s (${percent}% slower)"
elif (( $(echo "$diff < 0" | bc -l) )); then
abs_diff=$(echo "scale=2; -1 * $diff" | bc)
abs_percent=$(echo "scale=1; -1 * $percent" | bc)
echo " -${abs_diff}s (${abs_percent}% faster)"
else
echo " No difference (0%)"
fi
echo ""
# Show all individual results
echo "All timings:"
echo " Direct: ${direct_times[*]}"
echo " Agent: ${agent_times[*]}"