Does caching calculated loop indexes make a difference?
Does caching calculated loop indexes make a difference? Recently I was reviewing code to a real time financial application. Within a major for-loop construct, I came across the following subset of C# code:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
for (int index = 1; index < maxLoops; index++) { //Did some stuff _iSeries1[index] = _coeff1*MarketSeries.Close[index] + _coeff2*_iSeries1[index - 1]; _iSeries2[index] = _coeff1*_iSeries1[index] + _coeff2*_iSeries2[index - 1]; _iSeries3[index] = _coeff1*_iSeries2[index] + _coeff2*_iSeries3[index - 1]; _iSeries4[index] = _coeff1*_iSeries3[index] + _coeff2*_iSeries4[index - 1]; _iSeries5[index] = _coeff1*_iSeries4[index] + _coeff2*_iSeries5[index - 1]; _iSeries6[index] = _coeff1*_iSeries5[index] + _coeff2*_iSeries6[index - 1]; //Did more stuff in which objects and arrays were frequently accessed with [index - 1] } |
Look how many times [index… Continue Reading