How to prevent timeout on Solidity contract (not on tests or deployment config)

Consider the following function which is our current workaround to calculate the power of fractionals without overflowing:

function power(uint256 base, uint256 exponent, uint256 precision) public pure returns (uint256) {
      if (exponent == 0) {
        return 10**precision;
      } else if (exponent == 1) {
        return base;
      } else {
        uint256 answer = base;
        for (uint256 i = 0; i < exponent; i++) {
          answer = answer * base / (10**precision);
        }
        return answer;
      }
    }

Using Solidity 0.8.4 and Hardhat console.log I can confirm uint256 result = pow(1000555,exponent,6) (supposed to replicate 1.000555^x) is able to calculate all the values up to exponent = 10000 with a good level of accuracy, but it throws this error:
Error: Timeout of 20000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

If I try to deploy it to Rinkeby I can call a view function to get some of the first results, but starting around exponent>2000 it will start returning errored: [object Object]

I tried to look for ways to prevent this timeout from happening but I only find info about changes for tests or deployment config which don’t seem to prevent the issue above.

What changes need to be made to the code so that the timeout is prevented and all the values can be read?