-
-
Save IllIllI000/ec0e4e6c4f52a6bca158f137a3afd4ff 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: MIT | |
pragma solidity 0.8.13; // optimize 200 | |
/** | |
* @title DivVsShr | |
* @author IllIllI | |
*/ | |
contract DivVsShr { | |
// x = 999 : 21517 gas | |
function testShr_Pj(uint256 x) external pure returns(uint256) { | |
require(x != 0); | |
uint256 result; | |
result = x >> 1; | |
return result; | |
} | |
// x = 999 : 21537 gas | |
function testDiv_ebK(uint256 x) external pure returns(uint256) { | |
require(x != 0); | |
uint256 result; | |
result = x / 2; | |
return result; | |
} | |
// x = 999 : 21500 | |
function testDivUnch_Ghr(uint256 x) external pure returns(uint256) { | |
require(x != 0); | |
uint256 result; | |
unchecked { result = x / 2; } | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment