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?
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityYes. 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