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 ?

        Cardano.ExUnits.new(Cardano.BigNum.from_str("1754991"), Cardano.BigNum.from_str("652356532"))

        :

        Cardano.ExUnits.new(Cardano.BigNum.from_str("4254991"), Cardano.BigNum.from_str("1002356532"))

    const r = Cardano.Redeemer.new(

        Cardano.RedeemerTag.new_spend(),

        await toBigNum(index),

        redeemerData,

        exUnits

    );

but it is pretty lame.