-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalt_performance.sh
executable file
·71 lines (58 loc) · 1.52 KB
/
alt_performance.sh
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
#!/bin/bash
URL="http://localhost:3000"
REQUESTS=1000
OUTPUT_FILE="output.txt"
OUTPUT_FORMAT="HTTP_CODE: %{http_code}, TIME_TOTAL: %{time_total}, SIZE: %{size_request}\n"
exec 3>"$OUTPUT_FILE"
FILES=("hello.html" "table.html" "/")
make_request() {
local file="$1"
local url="$URL"
if [ "$file" != "/" ]; then
url="$url/$file"
fi
curl -o /dev/null -s -w "$OUTPUT_FORMAT" "$url" >&3
}
for ((i=0; i<REQUESTS; i++))
do
make_request "table.html" &
done
wait
exec 3>&-
calculate_statistics() {
local count="$1"
OUTPUT=$(awk -v count=$count '
BEGIN {
sum = 0; # Initialize sum
sumsq = 0; # Initialize sum of squares for stddev calculation
max = -1; # Initialize max value
min = 1e9; # Initialize min value
}
{
gsub(/,/, "");
$4 = $4 * 1000
sum += $4
sumsq += $4 * $4
if ($4 > max) max = $4 # Calculate max
if ($4 < min) min = $4 # Calculate min
}
END {
if (count > 0) {
average = (sum / count);
variance = (sumsq / count) - (average * average);
stdev = sqrt(variance);
print count, average, stdev, max, min; # Print the sum, average age, and count
} else {
print 0, 0, 0, 0, 0;
}
}
' "$OUTPUT_FILE");
read -r count average stdev max min <<< "$OUTPUT"
export count average stdev max min
}
calculate_statistics $REQUESTS;
echo "Count: $count"
echo "Average TIME_TOTAL: $average ms"
echo "stdev TIME_TOTAL: $stdev ms"
echo "max TIME_TOTAL: $max ms"
echo "min TIME_TOTAL: $min ms"