2

If a function has no loops, should the gas usage be identical every time it's called with the same variables?

Should the gas used be the same on testrpc as it is on mainnet?

1 Answer 1

6

Yes. Under the exact same circumstances, the exact same amount of gas will be used on every network.

Keep in mind that a function can also read things like msg.sender, block.number, this.address, this.balance or read contract state and behave differently based on their values. That could create a difference in gas consumption, even if the function is passed the same arguments.

Also keep in mind that writing to a storage variable with value 0 can cost more gas than if it was non-zero

Your Answer

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

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