I don't know how much more anyone can help you optimize what you are doing because I don't know what's going on behind the scenes (outside of the context of the snippet of code you pasted above, or what's really going on inside your MyFormula
function).
One optimization question I have would be: why are you storing everything as NSNumber
objects anyways and not an array of doubles
? The only advantage (that I can currently see) to doing that is if you're passing your NSNumber
objects along in an NSArray
, NSSet
or NSDictionary
that gets written out to disk or passed along in an NSNotification
or.
But some of the things I would do would include getting rid of that extra, unnecessary call to objectForKey
:
for (NSNumber * myNumber in temp_target_results)
{
formula_score = MyFormula([myNumber doubleValue]);
[target_results setObject:[NSNumber numberWithDouble:formula_score] forKey:[myNumber stringValue]];
}
Another consideration here:
Your target_results
appears to not be a NSMutableSet
because you are doing a NSMutableDictionary
method of setObject:forKey:
. If target_results
really was a NSMutableSet
, you'd only need to call:
[target_results addObject: [NSNumber numberWithDouble: formula_score]];