-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·67 lines (50 loc) · 1.38 KB
/
run.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
#!/usr/bin/env bash
NUM_CONNECTIONS=1000
NUM_SAMPLES=3
SERVER_PORT=5559
# Run benchmark against server by measuring the time it takes to create
# NUM_CONNECTIONS to it.
benchmark() {
local start_server="$1"
for i in $(seq 1 "$NUM_SAMPLES"); do
printf "sample %d: " "$i"
# Start server in background.
eval "$start_server" &
# Create NUM_CONNECTIONS to server.
conns_created=0
while [ "$conns_created" -lt "$NUM_CONNECTIONS" ]; do
if ! nc -z 127.0.0.1 "$SERVER_PORT"; then
continue
fi
conns_created=$((conns_created + 1))
done
wait
done
}
# Print current time in millis.
now() {
local nanos
nanos=$(date +%s%N)
echo $((nanos / 1000000))
}
# Starts a simple server.
start_simpleserver() {
local name=$1
local exe=$2
local start_time
start_time=$(now)
eval "$exe"
local end_time
end_time=$(now)
echo "$name accepted $NUM_CONNECTIONS connections in $((end_time - start_time))ms."
}
# Start the simple server written in C.
start_simpleserverc() {
start_simpleserver "simpleserver-c" ./bin/simpleserver-c
}
# Start the simple server written in Python.
start_simpleserverpython() {
start_simpleserver "simplerserver-python" ./simpleserver/python/server.py
}
benchmark "start_simpleserverc"
benchmark "start_simpleserverpython"