Skip to content

Instantly share code, notes, and snippets.

@DadeKuma
Created August 21, 2023 15:12
Show Gist options
  • Save DadeKuma/931ce6794a050201ec6544dbcc31316c to your computer and use it in GitHub Desktop.
Save DadeKuma/931ce6794a050201ec6544dbcc31316c to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;
contract Gas {
// 37
function notOptimized(bool a, bool b) external returns(uint gasUsed){
uint startGas = gasleft();
if(a && b) {
}
gasUsed = startGas - gasleft();
}
// 7
function optimized(bool a, bool b) external returns(uint gasUsed){
uint startGas = gasleft();
if(a) {
if(b) {
}
}
gasUsed = startGas - gasleft();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment