#!/bin/bash

mkdir -p /media/nameme
mount -t tmpfs -o size=1348M tmpfs /media/nameme/
cd /media/nameme/


rm out.txt
echo "Start test" >> /root/out.txt
apt-get -y install mc atop screen pbzip2 sysbench

CPU=$(cat /proc/cpuinfo  | grep -c processor)
((CPU--))

for i in `seq 0 $CPU`;
 do
  echo "performance" > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor
 done

rm ports.tar
wget http://test.artplanet.su/ports.tar

rm myfile.tar.bz2
START=$(($(date +%s%N)/1000000))
tar jcf myfile.tar.bz2 ports.tar 
END=$(($(date +%s%N)/1000000))
DIFF=$(( $END - $START ))
echo "Create bzip2 arhive in $DIFF miliseconds (one core)" >> /root/out.txt

rm myfile.tar.bz2
START=$(($(date +%s%N)/1000000))
tar cf myfile.tar.bz2 --use-compress-prog=pbzip2 ports.tar 
END=$(($(date +%s%N)/1000000))
DIFF=$(( $END - $START ))
echo "Create bzip2 arhive in $DIFF miliseconds (multi core)" >> /root/out.txt
rm myfile.tar.bz2


echo "Single Core test by sysbench" >> /root/out.txt
sysbench --test=cpu --cpu-max-prime=100000 run >> /root/out.txt

echo "Multi Thread test by sysbench" >> /root/out.txt
CPU=$(cat /proc/cpuinfo  | grep -c processor)
sysbench --test=cpu --cpu-max-prime=100000 --num-threads=$CPU run >> /root/out.txt
