Complete the code to declare a gas variable initialized to zero.
uint256 gasUsed = [1];The gasUsed variable should start at zero to measure gas consumption properly.
Complete the code to record the starting gas before a function call.
uint256 startGas = [1]();gasleft() returns the remaining gas at the current point in execution.
Fix the error in calculating gas used after function execution.
gasUsed = startGas - [1]();gasleft() must be called as a function to get current gas left.
Fill both blanks to create a function that returns gas used by a call.
function measureGas() public returns (uint256) {
uint256 start = [1]();
// some operation
uint256 end = [2]();
return start - end;
}Both start and end gas measurements use gasleft() function to get current gas left.
Fill all three blanks to create a gas measurement wrapper function.
function gasWrapper() public returns (uint256) {
uint256 [1] = [2]();
performAction();
uint256 gasUsed = [1] - [3]();
return gasUsed;
}We declare startGas variable, assign gasleft() at start, then subtract gasleft() after action.
