Benchmarks of popular contract implementations in solidity
Benchmarks for popular implementations of contract standards.
⚠️ The gas usage shown in the benchmarks doesn't take into account the 21k gas added to every ethereum transaction
You can see benchmarks for different compiler versions on benchmarks/
The file data.json
provides a json format of all the data used in the benchmarks. That file is generated by running the command make json
.
We create a minimal implementation of each contract that uses the specific implementation as a base. Then for each of the methods we want to benchmark, we create a test contract that set the environment in the setUp
function and each test only runs the specific function we're benchmarking, trying to reduce the noise as much as possible.
The gas usage shown here is not 100% accurate, but it's good enough to be able to compare the gas usage between the implementations.
All tests are generated using the template files in templates
All tables in the readmes are generated using the scripts in scripts
There are many ways to contribute to this project
scripts
folderpip install -r requirements.txt
git clone --recurse-submodules https://github.com/alephao/solidity-benchmarks.git
src/
, the contract name and file name should follow the convention <Contract Type>_<Variation>
.mint
and safeMint
functions)contracts.<contract type>.variations
property on test-cases.yml, following the examples there.variants
var following the examples there. It should map the variant name you used in the contract like ERC721_<Variant>
to the name you want to appear on the table. E.g.:<Contract Type>_<Variation>_ERC2309
, and add an entry to the contracts.ERC721.ERC2309Variations
in the test-cases.yml
variations = {
"OZ": "OpenZeppelin",
"OZEnumerable": "OpenZeppelin Enumerable",
"OZConsecutive": "OpenZeppelin Consecutive",
"Solady": "Solady",
"Solmate": "Solmate",
"A": "ERC721A",
"B": "ERC721B",
"K": "ERC721K",
}
make codegen
make snapshot
make readme
make json
<Contract Type>.md
. (If you added a new ERC721, update the list on top of ERC721.md
)ERC20
ERC721
ERC1155