Skip to content

Instantly share code, notes, and snippets.

@DadeKuma
Last active March 25, 2024 13:54
Show Gist options
  • Save DadeKuma/dbe25aafceb14291294449e31b0973c5 to your computer and use it in GitHub Desktop.
Save DadeKuma/dbe25aafceb14291294449e31b0973c5 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: GPL-3.0
pragma solidity =0.8.19;
contract Gas {
// 20
function notOptimized() external view returns(uint gasUsed){
uint startGas = gasleft();
uint256 callStatus;
callStatus = address(this).balance;
gasUsed = startGas - gasleft();
}
// 20
function compilerOptimized() public view returns (uint gasUsed) {
uint startGas = gasleft();
uint256 callStatus;
callStatus = address(this).balance;
gasUsed = startGas - gasleft();
}
// 117
function optimized() external view returns(uint gasUsed){
uint startGas = gasleft();
uint256 callStatus;
assembly {
callStatus :=balance(address())
}
gasUsed = startGas - gasleft();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment