3 # Program: RunSafelyAndStable.sh
5 # Synopsis: This script runs another program three times by repeatedly
6 # invoking the RunSafely.sh script. It collects the timings of
7 # the program and reports the smallest one. The <outfile>.time
8 # file will reflect the time and result code of the fastest
12 # ./RunSafelyAndStable.sh <ulimit> <exitok> <infile> <outfile> \
15 # See the RunSafely.sh script for more details.
17 DIR
=${0%%`basename $0`}
25 # Run it the first time
26 ${DIR}/RunSafely.sh
$ULIMIT $EXITOK $INFILE $OUTFILE $PROGRAM $
*
28 mv $OUTFILE.
time $OUTFILE.time1
29 TIME1
=`grep program $OUTFILE.time1 | sed 's/^program//'`
30 echo "Program $PROGRAM run #1 time: $TIME1"
32 # Run it the second time
33 ${DIR}/RunSafely.sh
$ULIMIT $EXITOK $INFILE $OUTFILE $PROGRAM $
*
34 mv $OUTFILE.
time $OUTFILE.time2
35 TIME2
=`grep program $OUTFILE.time2 | sed 's/^program//'`
36 echo "Program $PROGRAM run #2 time: $TIME2"
38 # Run it the third time
39 ${DIR}/RunSafely.sh
$ULIMIT $EXITOK $INFILE $OUTFILE $PROGRAM $
*
40 mv $OUTFILE.
time $OUTFILE.time3
41 TIME3
=`grep program $OUTFILE.time3 | sed 's/^program//'`
42 echo "Program $PROGRAM run #3 time: $TIME3"
44 # Figure out which run had the smallest run time:
45 SHORTEST
=`echo -e "$TIME1 time1\n$TIME2 time2\n$TIME3 time3" | sort |
46 head -1 | sed "s|.*time||"`
48 echo "Program $PROGRAM run #$SHORTEST was fastest"
49 cp $OUTFILE.
time$SHORTEST $OUTFILE.
time