not sure if this is possible, but I was wondering if one function can calculate the gas cost of another function?

Also can a function run a series of computations to match the gas cost of the function?

function checkGasCostToRunFunctionX() public view returns(uint) {
  return uint(gasCostOfRunningFunctionX())

function functionX() public {
 10000000000000000000000 + 10000000000000000000000;

function cloneFunctionXGasCost() public {
// small computation
1 + 1;

function checkCloneFunctionCostsSameAsFunctionX() public view returns(uint) {
 if (gasCostOfFunctionX == gasCostOfCloneFunction) {
    return = true;

Your Answer

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

Browse other questions tagged or ask your own question.