solidity/test/benchmarks/run.sh

76 lines
2.8 KiB
Bash
Raw Normal View History

2022-11-22 19:07:38 +00:00
#!/usr/bin/env bash
#------------------------------------------------------------------------------
# Bash script to run optimizer performance tests.
# ------------------------------------------------------------------------------
# This file is part of solidity.
#
# solidity is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# solidity is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with solidity. If not, see <http://www.gnu.org/licenses/>
#
# (c) 2022 solidity contributors.
#------------------------------------------------------------------------------
set -euo pipefail
REPO_ROOT=$(cd "$(dirname "$0")/../../" && pwd)
SOLIDITY_BUILD_DIR=${SOLIDITY_BUILD_DIR:-${REPO_ROOT}/build}
2022-11-29 10:33:18 +00:00
output_dir=$(mktemp -d -t solc-benchmark-XXXXXX)
result_legacy_file="${output_dir}/benchmark-legacy.txt"
result_via_ir_file="${output_dir}/benchmark-via-ir.txt"
warnings_and_errors_file="${output_dir}/benchmark-warn-err.txt"
2022-11-22 19:07:38 +00:00
function cleanup() {
2022-11-29 10:33:18 +00:00
rm -r "${output_dir}"
exit
2022-11-22 19:07:38 +00:00
}
trap cleanup SIGINT SIGTERM
solc="${SOLIDITY_BUILD_DIR}/solc/solc"
benchmarks_dir="${REPO_ROOT}/test/benchmarks"
2023-01-10 12:16:59 +00:00
benchmarks=("chains.sol" "OptimizorClub.sol" "verifier.sol")
2022-11-22 19:07:38 +00:00
time_bin_path=$(type -P time)
2022-11-29 10:33:18 +00:00
for input_file in "${benchmarks[@]}"
2022-11-29 10:33:18 +00:00
do
2022-11-29 10:33:18 +00:00
input_path="${benchmarks_dir}/${input_file}"
2022-11-22 19:07:38 +00:00
2022-11-29 10:33:18 +00:00
solc_command_legacy=("${solc}" --optimize --bin --color "${input_path}")
solc_command_via_ir=("${solc}" --via-ir --optimize --bin --color "${input_path}")
2022-11-22 19:07:38 +00:00
2022-11-29 10:33:18 +00:00
# Legacy can fail.
"${time_bin_path}" --output "${result_legacy_file}" --format "%e" "${solc_command_legacy[@]}" >/dev/null 2>>"${warnings_and_errors_file}"
"${time_bin_path}" --output "${result_via_ir_file}" --format "%e" "${solc_command_via_ir[@]}" >/dev/null 2>>"${warnings_and_errors_file}"
2022-11-22 19:07:38 +00:00
2022-11-29 10:33:18 +00:00
time_legacy=$(<"${result_legacy_file}")
time_via_ir=$(<"${result_via_ir_file}")
2022-11-29 10:33:18 +00:00
2022-11-29 10:33:18 +00:00
echo "======================================================="
echo " ${input_file}"
echo "-------------------------------------------------------"
echo "legacy pipeline took ${time_legacy} seconds to execute."
echo "via-ir pipeline took ${time_via_ir} seconds to execute."
echo "======================================================="
2022-11-29 10:33:18 +00:00
done
2022-11-22 19:07:38 +00:00
2022-11-29 10:33:18 +00:00
echo
echo "======================================================="
echo "Warnings and errors generated during run:"
echo "======================================================="
echo "$(<"${warnings_and_errors_file}")"
2022-11-22 19:07:38 +00:00
cleanup