forked from ethereum/solidity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ethereum#13734 from ethereum/add_perf_benchmarks
Add performance benchmarks.
- Loading branch information
Showing
2 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
// This is an adapted version of StdCheats by foundry: | ||
// https://github.com/foundry-rs/forge-std/blob/master/src/StdCheats.sol | ||
contract StdCheatsSafe { | ||
struct Chain { | ||
string name; | ||
uint256 chainId; | ||
string rpcUrl; | ||
} | ||
|
||
struct Chains { | ||
Chain Anvil; | ||
Chain Hardhat; | ||
Chain Mainnet; | ||
Chain Goerli; | ||
Chain Sepolia; | ||
Chain Optimism; | ||
Chain OptimismGoerli; | ||
Chain ArbitrumOne; | ||
Chain ArbitrumOneGoerli; | ||
Chain ArbitrumNova; | ||
Chain Polygon; | ||
Chain PolygonMumbai; | ||
Chain Avalanche; | ||
Chain AvalancheFuji; | ||
Chain BnbSmartChain; | ||
Chain BnbSmartChainTestnet; | ||
Chain GnosisChain; | ||
} | ||
|
||
Chains stdChains; | ||
|
||
function f(string[2][] memory rpcs) public returns (uint256) { | ||
stdChains = Chains({ | ||
Anvil: Chain("Anvil", 31337, "http://127.0.0.1:8545"), | ||
Hardhat: Chain("Hardhat", 31337, "http://127.0.0.1:8545"), | ||
Mainnet: Chain("Mainnet", 1, "https://api.mycryptoapi.com/eth"), | ||
Goerli: Chain("Goerli", 5, "https://goerli.infura.io/v3/84842078b09946638c03157f83405213"), | ||
Sepolia: Chain("Sepolia", 11155111, "https://rpc.sepolia.dev"), | ||
Optimism: Chain("Optimism", 10, "https://mainnet.optimism.io"), | ||
OptimismGoerli: Chain("OptimismGoerli", 420, "https://goerli.optimism.io"), | ||
ArbitrumOne: Chain("ArbitrumOne", 42161, "https://arb1.arbitrum.io/rpc"), | ||
ArbitrumOneGoerli: Chain("ArbitrumOneGoerli", 421613, "https://goerli-rollup.arbitrum.io/rpc"), | ||
ArbitrumNova: Chain("ArbitrumNova", 42170, "https://nova.arbitrum.io/rpc"), | ||
Polygon: Chain("Polygon", 137, "https://polygon-rpc.com"), | ||
PolygonMumbai: Chain("PolygonMumbai", 80001, "https://rpc-mumbai.matic.today"), | ||
Avalanche: Chain("Avalanche", 43114, "https://api.avax.network/ext/bc/C/rpc"), | ||
AvalancheFuji: Chain("AvalancheFuji", 43113, "https://api.avax-test.network/ext/bc/C/rpc"), | ||
BnbSmartChain: Chain("BnbSmartChain", 56, "https://bsc-dataseed1.binance.org"), | ||
BnbSmartChainTestnet: Chain("BnbSmartChainTestnet", 97, "https://data-seed-prebsc-1-s1.binance.org:8545"), | ||
GnosisChain: Chain("GnosisChain", 100, "https://rpc.gnosischain.com") | ||
}); | ||
|
||
for (uint256 i = 0; i < rpcs.length; i++) { | ||
(string memory name, string memory rpcUrl) = (rpcs[i][0], rpcs[i][1]); | ||
// forgefmt: disable-start | ||
if (isEqual(name, "anvil")) stdChains.Anvil.rpcUrl = rpcUrl; | ||
else if (isEqual(name, "hardhat")) stdChains.Hardhat.rpcUrl = rpcUrl; | ||
else if (isEqual(name, "mainnet")) stdChains.Mainnet.rpcUrl = rpcUrl; | ||
else if (isEqual(name, "goerli")) stdChains.Goerli.rpcUrl = rpcUrl; | ||
else if (isEqual(name, "sepolia")) stdChains.Sepolia.rpcUrl = rpcUrl; | ||
else if (isEqual(name, "optimism")) stdChains.Optimism.rpcUrl = rpcUrl; | ||
else if (isEqual(name, "optimism_goerli", "optimism-goerli")) stdChains.OptimismGoerli.rpcUrl = rpcUrl; | ||
else if (isEqual(name, "arbitrum_one", "arbitrum-one")) stdChains.ArbitrumOne.rpcUrl = rpcUrl; | ||
else if (isEqual(name, "arbitrum_one_goerli", "arbitrum-one-goerli")) stdChains.ArbitrumOneGoerli.rpcUrl = rpcUrl; | ||
else if (isEqual(name, "arbitrum_nova", "arbitrum-nova")) stdChains.ArbitrumNova.rpcUrl = rpcUrl; | ||
else if (isEqual(name, "polygon")) stdChains.Polygon.rpcUrl = rpcUrl; | ||
else if (isEqual(name, "polygon_mumbai", "polygon-mumbai")) stdChains.PolygonMumbai.rpcUrl = rpcUrl; | ||
else if (isEqual(name, "avalanche")) stdChains.Avalanche.rpcUrl = rpcUrl; | ||
else if (isEqual(name, "avalanche_fuji", "avalanche-fuji")) stdChains.AvalancheFuji.rpcUrl = rpcUrl; | ||
else if (isEqual(name, "bnb_smart_chain", "bnb-smart-chain")) stdChains.BnbSmartChain.rpcUrl = rpcUrl; | ||
else if (isEqual(name, "bnb_smart_chain_testnet", "bnb-smart-chain-testnet")) stdChains.BnbSmartChainTestnet.rpcUrl = rpcUrl; | ||
else if (isEqual(name, "gnosis_chain", "gnosis-chain")) stdChains.GnosisChain.rpcUrl = rpcUrl; | ||
// forgefmt: disable-end | ||
} | ||
return 0; | ||
} | ||
|
||
function isEqual(string memory a, string memory b) private pure returns (bool) { | ||
return keccak256(abi.encode(a)) == keccak256(abi.encode(b)); | ||
} | ||
|
||
function isEqual(string memory a, string memory b, string memory c) private pure returns (bool) { | ||
return keccak256(abi.encode(a)) == keccak256(abi.encode(b)) | ||
|| keccak256(abi.encode(a)) == keccak256(abi.encode(c)); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/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} | ||
|
||
result_legacy_file=$(mktemp -t benchmark-legacy-XXXXXX.txt) | ||
result_via_ir_file=$(mktemp -t benchmark-via-ir-XXXXXX.txt) | ||
|
||
function cleanup() { | ||
rm "${result_legacy_file}" | ||
rm "${result_via_ir_file}" | ||
exit | ||
} | ||
|
||
trap cleanup SIGINT SIGTERM | ||
|
||
solc="${SOLIDITY_BUILD_DIR}/solc/solc" | ||
benchmarks_dir="${REPO_ROOT}/test/benchmarks" | ||
chains_sol="${benchmarks_dir}/chains.sol" | ||
time_bin_path=$(type -P time) | ||
|
||
solc_command_legacy=("${solc}" --optimize --bin "${chains_sol}") | ||
solc_command_via_ir=("${solc}" --via-ir --optimize --bin "${chains_sol}") | ||
|
||
"${time_bin_path}" --output "${result_legacy_file}" --format "%e" "${solc_command_legacy[@]}" >/dev/null | ||
"${time_bin_path}" --output "${result_via_ir_file}" --format "%e" "${solc_command_via_ir[@]}" >/dev/null | ||
|
||
time_legacy=$(<"${result_legacy_file}") | ||
time_via_ir=$(<"${result_via_ir_file}") | ||
|
||
echo "=======================================================" | ||
echo "legacy pipeline took ${time_legacy} seconds to execute." | ||
echo "via-ir pipeline took ${time_via_ir} seconds to execute." | ||
echo "=======================================================" | ||
|
||
cleanup | ||
|