#!/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 across localhost)" 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 ;; *) die "unknown benchmark type $bench" ;; esac done