forked from pothos/tiny-http
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.travis-bench
executable file
·61 lines (50 loc) · 1.61 KB
/
.travis-bench
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
#!/bin/bash
kill_child_processes() {
isTopmost=$1
curPid=$2
childPids=`ps -o pid --no-headers --ppid ${curPid}`
for childPid in $childPids
do
kill_child_processes 0 $childPid
done
if [ $isTopmost -eq 0 ]; then
disown $curPid &> /dev/null
kill -9 $curPid &> /dev/null
fi
}
start_bench() {
concurrency=$1
num=50000
# benchmarking nodejs
echo "Benchmarking nodejs (concurrency: ${concurrency})"
(node bench.js) & (sleep 1 ; exec ab -n ${num} -c ${concurrency} http://localhost:9615/ 2> /dev/null | grep "per second")
# benchmarking tiny-http
echo "Benchmarking tiny-http (concurrency: ${concurrency})"
(./hello_world 1> /dev/null) & (sleep 1 ; exec ab -n ${num} -c ${concurrency} http://localhost:9975/ 2> /dev/null | grep "per second")
# benchmarking apache2
echo "Benchmarking apache2 (concurrency: ${concurrency})"
exec ab -n ${num} -c ${concurrency} http://localhost/ 2> /dev/null | grep "per second"
kill_child_processes 1 $$
}
# Ctrl-C trap. Catches INT signal
trap "kill_child_processes 1 $$; exit 0" INT
# building tiny-http
echo "Building tiny-http"
cargo build --release
rustc --opt-level=3 -Z lto -o hello_world -L target/release -L target/release/deps examples/hello-world.rs
# building nodejs app
echo "var http = require('http');" > bench.js
echo "http.createServer(function (req, res) {" >> bench.js
echo " res.writeHead(200, {'Content-Type': 'text/plain'});" >> bench.js
echo " res.end(\"hello world\");" >> bench.js
echo "}).listen(9615);" >> bench.js
#
start_bench 1
start_bench 2
start_bench 4
start_bench 8
start_bench 16
start_bench 32
start_bench 64
# cleanup
kill_child_processes 1 $$