Here is my code.
contract Demo {
function add1(uint256 a, uint256 b) public pure returns (uint256) {
if (a==0) {
return 0;
}
uint256 c = a + b;
return c;
}
}
contract Test {
Demo demo = new Demo();
function testGas() public {
uint256 startGas = gasleft();
demo.add1(1, 2);
uint256 endGas = gasleft();
uint256 gasUsage1 = startGas - endGas;
startGas = gasleft();
demo.add1(1, 2);
endGas = gasleft();
uint256 gasUsage2 = startGas - endGas;
}
}
The gasUsage1 is 6434 and gasUsage2 is 1919.
When the function is called a third time, the gas usage is the same as the second time.
I tested other functions and the results were the same.