#!/usr/bin/env bash

batch(){
  levels="$1"
  spread="$2"
  N="$3"
  pre="${levels}x${spread}_"
  eval "$(pat bashrc)"
  pat use 1.6
  ./benchmark.py run ${pre}1.6_1.runs $levels $spread $N
  ./benchmark.py run ${pre}1.6_2.runs $levels $spread $N
  pat use 1.7
  ./benchmark.py run ${pre}1.7_1.runs $levels $spread $N
  ./benchmark.py run ${pre}1.7_2.runs $levels $spread $N
  echo ---
  echo "Levels: $levels  Spread: $spread"
  echo ---
  echo 'Average of the 1.6 runs:'
  ./benchmark.py combine ${pre}1.6_1.runs ${pre}1.6_2.runs ${pre}1.6_all.runs
  echo ---
  echo 'Average of the 1.7 runs:'
  ./benchmark.py combine ${pre}1.7_1.runs ${pre}1.7_2.runs ${pre}1.7_all.runs
  echo ---
  echo 'This is the variation between the two 1.6 runs'
  echo '(expecting roughly 1.0 everywhere)'
  ./benchmark.py compare ${pre}1.6_1.runs ${pre}1.6_2.runs
  echo ---
  echo 'This is the variation between the two 1.7 runs'
  echo '(expecting roughly 1.0 everywhere)'
  ./benchmark.py compare ${pre}1.7_1.runs ${pre}1.7_2.runs
  echo ---
  echo "Levels: $levels  Spread: $spread"
  echo 'svn 1.7 takes <x> times as long as svn 1.6'
  echo '(when a value is smaller than 1.0, svn 1.7 is faster)'
  echo 'min: the shortest run of 1.7 took <x> times as long as the shortest'
  echo 'run of 1.6. -- max: the longest run of 1.7 took <x> times as long as'
  echo 'the longest run of 1.6 -- avg: just replace "longest" with "average" ;)'
  ./benchmark.py compare ${pre}1.6_all.runs ${pre}1.7_all.runs
}

N=3
al=4
as=4
bl=100
bs=1
cl=1
cs=100

{
echo 
echo 
echo '********************************************************************'
echo '********************************************************************'
echo '********************************************************************'
echo 
echo 
date
echo 

batch $al $as $N
batch $bl $bs $N
batch $cl $cs $N

echo ---
echo ---
echo combining 1.6...
./benchmark.py combine ${al}x${as}_1.6_all.runs ${bl}x${bs}_1.6_all.runs tmp.runs
echo combining 1.6...
./benchmark.py combine tmp.runs ${cl}x${cs}_1.6_all.runs 1.6_total.runs
rm tmp.runs

echo combining 1.7...
./benchmark.py combine ${al}x${as}_1.7_all.runs ${bl}x${bs}_1.7_all.runs tmp.runs
echo combining 1.7...
./benchmark.py combine tmp.runs ${cl}x${cs}_1.7_all.runs 1.7_total.runs
rm tmp.runs

./benchmark.py compare ${pre}1.6_all.runs ${pre}1.7_all.runs
echo =========================================================================
echo "Results for Levels: $al, Spread: $as"
pre="${al}x${as}_"
./benchmark.py compare ${pre}1.6_all.runs ${pre}1.7_all.runs

echo =========================================================================
echo "Results for Levels: $bl, Spread: $bs"
pre="${bl}x${bs}_"
./benchmark.py compare ${pre}1.6_all.runs ${pre}1.7_all.runs

echo =========================================================================
echo "Results for Levels: $cl, Spread: $cs"
pre="${cl}x${cs}_"
./benchmark.py compare ${pre}1.6_all.runs ${pre}1.7_all.runs

echo =========================================================================
echo 'svn 1.7 takes <x> times as long as svn 1.6'
echo '(when a value is smaller than 1.0, svn 1.7 is faster)'
echo 'min: the shortest run of 1.7 took <x> times as long as the shortest'
echo 'run of 1.6. -- max: the longest run of 1.7 took <x> times as long as'
echo 'the longest run of 1.6 -- avg: just replace "longest" with "average" ;)'
./benchmark.py compare 1.6_total.runs 1.7_total.runs
} >>results.txt 2>&1

