1

What is the more gas-efficient expression to check for non-equality? Is it n != 0, or n > 0?

1 Answer 1

0

According to the Ethereum Yellow Paper (Appendix G - Fee Schedule), the gas costs for the relevant opcodes are as follows:

The first expression (n != 0) utilizes both the EQ and the ISZERO opcodes as follows: iszero(eq(x, 0)). While the second expression (n > 0) only utilizes the GT opcode as follows: gt(x, 0).

Therefore, the expression n > 0 is more gas-efficient than n != 0 by 3 gas units.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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