Skip to content

Commit

Permalink
update evaluate2.sh for new fork file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
hundredwatt committed Jan 9, 2024
1 parent facf3c1 commit 15acae6
Showing 1 changed file with 50 additions and 19 deletions.
69 changes: 50 additions & 19 deletions evaluate2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
if [ -z "$1" ]
then
echo "Usage: evaluate2.sh <fork name> (<fork name 2> ...)"
echo " for each fork, there must be a 'prepare_<fork name>.sh' script and a 'calculate_average_<fork name>.sh' script"
echo " there may be an 'additional_build_steps_<fork name>.sh' script too"
exit 1
fi

Expand All @@ -27,6 +29,7 @@ function check_command_installed {
exit 1
fi
}

check_command_installed java
check_command_installed mvn
check_command_installed hyperfine
Expand All @@ -44,31 +47,59 @@ ln -s measurements_1B.txt measurements.txt
set +o xtrace

echo ""
TEMP_FILE=$(mktemp)
HYPERFINE_OPTS="--warmup 1 --runs 5 --export-json $TEMP_FILE"
# For debugging:
# HYPERFINE_OPTS="$HYPERFINE_OPTS --show-output"

# Prepare commands for running benchmarks for each of the forks
filetimestamp=$(date +"%Y%m%d%H%M%S") # same for all fork.out files from this run
forks=()
for fork in "$@"; do
forks+=("./calculate_average_$fork.sh 2>&1")
# Use prepare script to invoke SDKMAN
if [ ! -f "./prepare_$fork.sh" ]; then
echo "Error: prepare script for $fork not found, expecting file ./prepare_$fork.sh"
exit 1
fi
source "./prepare_$fork.sh"

# Optional additional build steps
if [ -f "./additional_build_steps_$fork.sh" ]; then
./additional_build_steps_$fork.sh
fi

# Use hyperfine to run the benchmarks for each fork
HYPERFINE_OPTS="--warmup 1 --runs 5 --export-json $fork-$filetimestamp.out"
# For debugging:
# HYPERFINE_OPTS="$HYPERFINE_OPTS --show-output"
hyperfine $HYPERFINE_OPTS "./calculate_average_$fork.sh 2>&1"
done

# Use hyperfine to run the benchmarks for each fork
hyperfine $HYPERFINE_OPTS "${forks[@]}"
# Print the 'Summary' in bold and white
BOLD_WHITE='\033[1;37m'
CYAN='\033[0;36m'
GREEN='\033[0;32m'
PURPLE='\033[0;35m'
RESET='\033[0m' # No Color

# The slowest and the fastest runs are discarded
# The mean value of the remaining three runs is the result for that contender
echo ""
echo "fork,trimmed_mean"
jq -r '.results[] | [ .command, ((.times | sort) | .[1:-1] | add / length) ] | join(",")' $TEMP_FILE \
| perl -pe 's/^[.]\/calculate_average_(\w+).*,/$1,/'
echo -e "${BOLD_WHITE}Summary${RESET}"

# Output the raw times for each command
echo ""
echo "fork,raw_times"
jq -r '.results[] | [.command, (.times | join(","))] | join(",")' $TEMP_FILE \
| perl -pe 's/^[.]\/calculate_average_(\w+).*?,/$1,/'
forks=()
for fork in "$@"; do
# Trimmed mean = The slowest and the fastest runs are discarded, the
# mean value of the remaining three runs is the result for that contender
trimmed_mean=$(jq -r '.results[0].times | .[1:-1] | add / length' $fork-$filetimestamp.out)
raw_times=$(jq -r '.results[0].times | join(",")' $fork-$filetimestamp.out)

if [ "$fork" == "$1" ]; then
color=$CYAN
elif [ "$fork" == "$2" ]; then
color=$GREEN
else
color=$PURPLE
fi

echo -e " ${color}$fork${RESET}: trimmed mean ${BOLD_WHITE}$trimmed_mean${RESET}, raw times ${BOLD_WHITE}$raw_times${RESET}"
done

rm $TEMP_FILE
echo ""
echo "Raw results saved to file(s):"
for fork in "$@"; do
echo " $fork-$filetimestamp.out"
done

0 comments on commit 15acae6

Please sign in to comment.