Skip to content

Instantly share code, notes, and snippets.

@IllIllI000
Created July 9, 2022 18:16
Show Gist options
  • Save IllIllI000/ec0e4e6c4f52a6bca158f137a3afd4ff to your computer and use it in GitHub Desktop.
Save IllIllI000/ec0e4e6c4f52a6bca158f137a3afd4ff to your computer and use it in GitHub Desktop.
// 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