Suppose I have a solidty smart contract that calls getReserves of a certain pair say weth/token. Now my goal is to sum these two reserves, reserveWeth + reserveToken. Would it be faster to execute this computation on the solidity smart contract directly after fetching the reserves or instead, to await for the return value of calling the smart contract to get reserves and then performing this operation on my computer using a javascript file.
Basically what is faster
option1
const reserves = await fetchingData.getReserves(weth,token) //runs on javascript file
//this will call the contract fetchingData
contract fetchingData {
function getReserves(weth,token){
const reserves = getReserves(weth, token)
const sum = reserves[0] + reserve[1]
return sum
}
//this returns the sum to my javascript file
}
option2
const reserves = await fetchingData.getReserves(weth,token) //runs on javascript
//this will call the contract fetchingData
contract fetchingData {
function getReserves(weth,token){
const reserves = getReserves(weth, token)
return reserves
}
//this returns the reserves (not the sum) to my javascript file
}
//on my javascript file, using the return value I sum them
const sum = reserves[0] + [1];
now consider this over a large computation operation, certainly there will be a speed difference. Which is faster ? Also when you call a smart contract's code where does it execute?