The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/bin/env bash

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

# Where are the svn binaries you want to benchmark?
if [ "$USER" = "neels" ]; then
  SVN_1_6="$HOME/pat/stable/prefix/bin/svn"
  SVN_trunk="$HOME/pat/trunk/prefix/bin/svn"
else
  SVN_1_6="$HOME/src/svn-1.6.x/subversion/svn/svn"
  SVN_trunk="$HOME/src/svn/subversion/svn/svn"
fi

benchmark="$PWD/benchmark.py"

parent="$(date +"%Y%m%d-%H%M%S")"
inital_workdir="$PWD"
mkdir "$parent"
cd "$parent"
pwd


batch(){
  levels="$1"
  spread="$2"
  N="$3"
  pre="${levels}x${spread}_"
  echo
  echo "---------------------------------------------------------------------"
  echo
  echo "Results for dir levels: $levels  spread: $spread"
  "$benchmark" "--svn=${SVN_1_6}" run ${pre}1.6 $levels $spread $N >/dev/null
  "$benchmark" "--svn=${SVN_trunk}" run ${pre}trunk $levels $spread $N > /dev/null
  "$benchmark" compare ${pre}1.6 ${pre}trunk
}

N=6
al=5
as=5
bl=100
bs=1
cl=1
cs=100

##DEBUG
#N=1
#al=1
#as=1
#bl=2
#bs=1
#cl=1
#cs=2
##DEBUG


{
started="$(date)"
echo "Started at $started"
echo ""

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

echo ""
echo =========================================================================
echo ""
"$benchmark" combine total_1.6 *x*_1.6 >/dev/null
"$benchmark" combine total_trunk *x*_trunk >/dev/null

echo "comparing averaged totals..."
"$benchmark" compare total_1.6 total_trunk

echo ""
echo "Had started at $started,"
echo "       done at $(date)"
pwd
} 2>&1 | tee results.txt

cd "$inital_workdir"
if [ -f "$parent/total_trunk" ]; then
  rm -rf "$parent"
fi