Last active
March 25, 2024 13:54
-
-
Save DadeKuma/dbe25aafceb14291294449e31b0973c5 to your computer and use it in GitHub Desktop.
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
// 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