REPO_URL=$1
DEV_FILE=$2
MOUNT_POINT=$3

umount $DEV_FILE
mount $DEV_FILE $MOUNT_POINT

cd $MOUNT_POINT
rm -rf test_repo
darcs-build get $REPO_URL --repodir test_repo
cd test_repo

FILES=$(darcs-build show files --no-directories)

run_commands () {
   for f in $FILES
   do

      # flush disk cache
      cd $HOME
      umount $DEV_FILE
      sync && echo 1 > /proc/sys/vm/drop_caches
      mount $DEV_FILE $MOUNT_POINT
      cd $MOUNT_POINT/test_repo

      T1=`date +"%s%N"`
      darcs-build $COMMAND $f > /dev/null
      T2=`date +"%s%N"`
      darcs-build $COMMAND $f > /dev/null
      T3=`date +"%s%N"`
      echo $f $(($T2-$T1)) $(($T3-$T2)) >> $HOME/$COMMAND\_$MODE\_time.txt
   done
}

darcs-build optimize --patch-index
COMMAND=changes
MODE=pi
run_commands

COMMAND=annotate
run_commands

darcs-build optimize --disable-patch-index
MODE=npi

run_commands

COMMAND=changes
run_commands
