Calculating memory and cpu for redeemer

Hi guys,

wanted to ask if there is a deterministic way on how to calculate memory and cpu that is be required to interact with smartcontract?

Currently I have a code that takes lower fee in case user decides to cancel sell offer but buying requires more due to more outputs

const exUnits = redeemerType == RedeemerType.Cancel ?"1754991"), Cardano.BigNum.from_str("652356532"))

        :"4254991"), Cardano.BigNum.from_str("1002356532"))

    const r =


        await toBigNum(index),




but it is pretty lame.