-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.sh
66 lines (55 loc) · 1.28 KB
/
benchmark.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
#!/bin/bash
# simple script to test the server
usage() {
echo "Usage: $0 [-n number of requests] [-p port] [-u url relative to localhost:port/ (Example: benchmark/puppies.html)]"
}
num_requests=100
port=8000
url="/benchmark/puppies/index.html"
while getopts "n:u:p:s:t:" o; do
case "${o}" in
n)
num_requests=${OPTARG}
;;
u)
url=${OPTARG}
;;
p)
port=${OPTARG}
;;
s)
html=${OPTARG}
;;
*)
usage
exit 1
;;
esac
done
# make temp directory
rm -rf temp && mkdir temp && cd temp/
test_url="http://localhost:$port/$url"
echo "Benchmark url: $test_url"
# start time
start=`date +%s%N`
# make num_requests
i=0
while [[ $i -le $num_requests ]]
do
if wget -r -q $test_url > /dev/null; then
let i=i+1
else
echo "wget failed! Make sure you have wget installed and the server is running on $port !"
exit 1
fi
done
# end time
end=`date +%s%N`
runtime=$((end-start))
# remove temp
cd ../ && rm -rf temp
# report results
echo "Made $num_requests requests"
echo "Total time: $(expr $runtime / 1000000000) s"
echo "Average time per request: $(expr $(expr $runtime / $num_requests) / 1000000) ms"
exit 0