if(num <= 10) revert();
And
if(num < 11) revert();
Which of these statements consume less gas?
If we could save gas, we need not use less than/greater than equal to. We can just use less than or greater than along with the next integer.
gasoptimizationSecuritysolidity
if(num <= 10) revert();
And
if(num < 11) revert();
Which of these statements consume less gas?
If we could save gas, we need not use less than/greater than equal to. We can just use less than or greater than along with the next integer.
Best Answer
LE (lower or equal) opcode does not exist on EVM, the operation is accomplished as a combination of existing opcodes. The specific combination will depend on the compiler version, optimizer, and code context, etc.
In that specific example the opcode for
is
and for
is
So, using
<
option will be 3 gas more expensive than using the<=
due to the extra ISZERO opcode. But, in some cases likeUsing
<=
will be the one costing 3 more gas.In conclusion, it depends on the code context which one is more efficient but, the 3-gas difference is negligible so, could consider using either.