I'm at the debugging/optimization phase with an iPhone app. I have one bottleneck left - the only place where the program has a noticeable lag, and it's in the following loop: (By the way, I've renamed the vars with letters and types. (The real names are much more human-readable in the actual app, but make little sense out of context, so I hope this is clear enough.) Here's the loop:
for(i=0;i<xLong; i+=yFloat*zShort){
aFloat=0.0;
for(int j=i;j<i+yFloat*zShort;j++){
aFloat=hArray[j]/kFloat;
}
bNSNumber = [NSNumber numberWithFloat:aFloat];
[cNSMutableArray addObject:bNSNumber];
}
All objection creation and clean-up is outside of this loop.
(It should be pretty straight forward what's happening here, but basically I have a very large array (in the millions) and I'm going through that array at chunks of yFloat*zShort length, adding all of the elements in that chunk, and inserting that final sum in another array. So if hArray is a million elements long, and my chunk length is 200, I'll sum the first 200 elements, insert that total in cNSMutableArray, and move on to the next 200 elements in hArray. In the end, cNSMutableArray will be 5000 elements long.)
When the outer loop is around 25k and the inner loop is around 200, this code takes about 4 seconds to run. I would sure like to get that down as much as possible, as in the real world, the outer loop might be quite a bit larger.
Any ideas how to quicken this up?
Thanks for any ideas you have!