-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimr4.sh
More file actions
executable file
·91 lines (74 loc) · 2.67 KB
/
simr4.sh
File metadata and controls
executable file
·91 lines (74 loc) · 2.67 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
#!/bin/bash
run_test() {
local payload=$1
local test_label=$2
# Use curl's built-in timing and capture output to a temp file
temp_file=$(mktemp)
# Measure time and capture response
start_time=$(date +%s.%N)
response=$(curl -s -w "\n%{time_total}" -X POST http://localhost:8000/api/v1/hackrx/run \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Authorization: Bearer febc0daceda23ebce03d324301d34ad3768494f0b52a39ffb4adaf083d8f9c5c" \
-d @"$payload" 2>/dev/null)
curl_exit_code=$?
end_time=$(date +%s.%N)
if [ $curl_exit_code -ne 0 ]; then
echo "Error: cURL command failed for $test_label"
return
fi
# Extract time from the last line and response from all but last line
time_taken=$(echo "$response" | tail -n1)
response_json=$(echo "$response" | head -n -1)
# Validate that time_taken is a number
if ! [[ $time_taken =~ ^[0-9]+\.?[0-9]*$ ]]; then
# Fallback to manual time calculation if curl timing fails
time_taken=$(echo "$end_time - $start_time" | bc -l)
fi
echo "=========================================="
echo "Response for $test_label:"
echo "$response_json"
echo ""
if echo "$response_json" | grep -q '"answers"'; then
echo "--- $test_label processed successfully in ${time_taken}s ---"
else
echo "Warning: $test_label not processed successfully."
fi
# Store the time taken in the array
times+=($(printf "%.3f" $time_taken))
echo ""
}
# Initialize time array
times=()
# Run tests
run_test "payloads/r41.json" "test 1 apis"
run_test "payloads/r42.json" "test 2 secret key"
run_test "payloads/r43.json" "test 3 language"
# Calculate and display statistics
echo "=========================================="
echo "TIMING STATISTICS:"
echo "=========================================="
# Display individual times
echo "Individual request times:"
for i in "${!times[@]}"; do
echo "Test $((i+1)): ${times[$i]}s"
done
# Calculate average using bc for precise floating point arithmetic
sum=0
for t in "${times[@]}"; do
sum=$(echo "$sum + $t" | bc -l)
done
if [ ${#times[@]} -gt 0 ]; then
average=$(echo "scale=3; $sum / ${#times[@]}" | bc -l)
echo ""
echo "Total requests: ${#times[@]}"
echo "Total time: $(printf "%.3f" $sum)s"
echo "Average time per request: ${average}s"
# Additional statistics
min_time=$(printf '%s\n' "${times[@]}" | sort -n | head -n1)
max_time=$(printf '%s\n' "${times[@]}" | sort -n | tail -n1)
echo "Fastest request: ${min_time}s"
echo "Slowest request: ${max_time}s"
else
echo "No successful requests to calculate average"
fi