0

i've read on a blog that it is most costly gas wise to write eg. x <= y than x < y + 1, do you have any ideea if it's true and why would that be the case? Except that blog I couldn't find anything else stating this. This is the blog in question:https://nftchance.medium.com/the-gas-efficient-way-of-building-and-launching-an-erc721-nft-project-for-2022-b3b1dac5f2e1

1
  • If you are doing those micro optimizations I'd you are doing something wrong. If you are serious about gas then write directly in assembly. Arithmetic operations in the EVM are very cheap I'd look for optimizing the more expensive operations first, like storage and memory allocations.
    – Ismael
    Mar 19, 2022 at 5:07

1 Answer 1

0

You might want to study the Ethereum Yellow Paper. All operations in the following set have the same gas cost.

Wverylow = {ADD, SUB, NOT, LT, GT, SLT, SGT, EQ, ISZERO, AND, OR, XOR, BYTE, SHL, SHR, SAR,
CALLDATALOAD, MLOAD, MSTORE, MSTORE8, PUSH*, DUP*, SWAP*}

To evaluate which of the statements this question refers to is more gas efficient, one would have to understand how the statements are translated into assembly code.

A more practical way to find out which of the statements is better could be, for example, the use of: https://web3js.readthedocs.io/en/v1.2.11/web3-eth.html#estimategas

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.