I'm coding for an application that has a function like this:
xArrayLength and yArrayLength aren't large, but the function can get called millions of times. I've noticed a significant amount of time in my program is spent fetching values from two dimensional arrays like this.Code:decimal totalValue; for(int i=0; i<xArrayLength; i++) { for(int j=0; j<yArrayLength;j++) { totalValue += currentValue[i,j] //currentValue is modular } } return totalValue;
My question: Does swapping the looping order of i and j change the speed of fetching values from the array? Would it affect the speed if the arraylengths were bigger? Is there anything else I can do to speed up the constant access to multi dimensional arrays in scenarios like this?




Reply With Quote