Skip to content

Instantly share code, notes, and snippets.

@0xbb
Created October 30, 2015 12:09
Show Gist options
  • Save 0xbb/b8e08a1814b4d5b48337 to your computer and use it in GitHub Desktop.
Save 0xbb/b8e08a1814b4d5b48337 to your computer and use it in GitHub Desktop.
Small bash script to unscientifically benchmark Virtual Private Server (VPS)
#!/bin/bash
apt-get install -y bzip2 gzip xz-utils php5-cli php5-xdebug wget time build-essential bc
rm -rf vpsmark-test
mkdir vpsmark-test
cd vpsmark-test
model=$(grep '^model name' -m1 /proc/cpuinfo | sed -r "s/model name.*: *(.*)/\1/")
cores=$(grep -c ^processor /proc/cpuinfo)
mhz=$(grep 'cpu MHz' -m1 /proc/cpuinfo | sed -r "s/cpu MHz.*: *(.*)/\1/")
mem=$(free -m | grep Mem: | sed -r "s/Mem: *([0-9]*).*/\1/")
echo "==========================================================="
echo "CPU Model: $model"
echo "Number of cores: $cores"
echo "CPU frequency: $mhz MHz"
echo "Total RAM: $mem MB"
dd if=/dev/urandom bs=1MB count=500 of=rand &> /dev/null
/usr/bin/time -f "Bzip2 500 MB: %es" bash -c "bzip2 -c rand > /dev/null"
/usr/bin/time -f "Gzip 500 MB: %es" bash -c "gzip -c rand > /dev/null"
/usr/bin/time -f "Xz 500 MB: %es" bash -c "xz -c rand > /dev/null"
/usr/bin/time -f "SHA512 500 MB: %es" bash -c "dd if=/dev/zero 2> /dev/null bs=1MB count=500 | sha512sum &> /dev/null"
read -d '' php <<"EOF"
<?php
function quicksort($array) {
if (count($array) <= 1) {
return $array;
}
$pivot_value = array_shift($array);
return array_merge(
quicksort(array_filter($array, function ($v) use($pivot_value) {return $v < $pivot_value;})),
array($pivot_value),
quicksort($higher = array_filter($array, function ($v) use($pivot_value) {return $v >= $pivot_value;}))
);
}
$a = [];
for($i = 0; $i < 50000; $i++){
$v = rand();
$a[] = $v;
sin($v) + sqrt($v);
htmlspecialchars("<script>alert('XSS')</script>" . implode(";",explode(";", "A;B;C;D;")));
}
$a = quicksort($a);
EOF
echo $php > bench.php
/usr/bin/time -f "PHP: %es" bash -c "php bench.php"
echo -n "IO 512 B: "
dd bs=512 count=2000000 if=/dev/zero of=tmp conv=fdatasync 2>&1| grep -E -o '[0-9]*(\.[0-9])* MB/s'
echo -n "IO 1 MB: "
dd bs=1MB count=500 if=/dev/zero of=tmp conv=fdatasync 2>&1| grep -E -o '[0-9]*(\.[0-9])* MB/s'
echo -n "Net AT: "
wget -O /dev/null 2>&1 http://debian.anexia.at/debian-cd/8.2.0/amd64/iso-cd/debian-8.2.0-amd64-CD-1.iso | grep -o -E '[0-9]*\.[0-9]* MB/s'
echo -n "Net SWE: "
wget -O /dev/null 2>&1 http://cdimage.debian.org/debian-cd/8.2.0/amd64/iso-cd/debian-8.2.0-amd64-CD-1.iso | grep -o -E '[0-9]*\.[0-9]* MB/s'
echo -n "Net US: "
wget -O /dev/null 2>&1 https://mirrors.kernel.org/debian-cd/8.2.0/amd64/iso-cd/debian-8.2.0-amd64-CD-1.iso | grep -o -E '[0-9]*\.[0-9]* MB/s'
wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.2.5.tar.xz &> /dev/null
tar xf linux-4.2.5.tar.xz
cd linux-4.2.5
make defconfig > /dev/null
/usr/bin/time -f "Kernel Compile: %es" bash -c "make -j$cores > /dev/null"
cd ..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment