summaryrefslogtreecommitdiff
path: root/benchmarker
blob: 3dea0770b3b2c15437cf884323fca4f29debf1b8 (plain)
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
#!/bin/sh

set -eu

die()
{
    echo "$@" 1>&2
    exit 1
}

gotcmd()
{
    command -v "$1" > /dev/null || die "Need command $1"
}

gotfile()
{
    test -e "$1" || die "Need file $1"
}

cpubench_xz()
{
    local filename
    local size

    size=1G
    filename="$(mktemp)"
    truncate -s 10G "$filename"

    echo "CPU benchmark (xz on a $size sparse file)"
    /bin/time --format="%e" xz -T0 < "$filename" > /dev/null
    rm -f "$filename"
}

network_localhost()
{
    local filename
    local port
    local size

    filename="$(mktemp)"
    port=3858
    size=10G
    truncate -s "$size" "$filename"

    echo "Network benchmark (netcat a $size sparse file to localhost)"
    nc -l localhost "$port" > /dev/null &
    /bin/time --format="%e" nc -N localhost "$port" < "$filename"
    rm -f "$filename"
}

netbench_remote()
{
    local filename
    local port
    local size
    local host

    filename="$(mktemp)"
    host="$BENCHMARK_REMOTE"
    port=3858
    size=10G
    truncate -s "$size" "$filename"

    echo "Network benchmark (netcat a $size sparse file to $host)"
    ssh "$host" "nc -l localhost $port > /dev/null" &
    /bin/time --format="%e" nc -N localhost "$port" < "$filename"
    rm -f "$filename"
}

for bench in "$@"
do
    case "$bench" in
	cpu)
	    cpubench_xz
	    ;;
	network-localhost)
	    netbench_localhost
	    ;;
	network-remote)
	    netbench_remote
	    ;;
	*)
	    die "unknown benchmark type $bench"
	    ;;
    esac
done