Re: Optimizing a loop
Re: Optimizing a loop
- Subject: Re: Optimizing a loop
- From: Wade Tregaskis <email@hidden>
- Date: Wed, 10 Aug 2011 08:27:00 -0700
> //This takes about 6 seconds each search for song*
> for (id key in songsDictionary) {
> NSString *thisSong = key;
> int suppliedCount = [stringValue length];
> int keyCount = [thisSong length];
> //Fuzzy matching
> if(suppliedCount > keyCount){
> match= [StringDistance stringDistance:thisSong
> :stringValue];
> } else {
> match= [StringDistance stringDistance:stringValue
> :thisSong];
> }
> //Get the very best match there is to be found for song.
> if(match < currentFoundValue){
> currentFoundValue = match;
> test = [songsDictionary objectForKey:thisSong];
> dis = [NSArray arrayWithObject:test];
> collection = [[MPMediaItemCollection alloc]
> initWithItems:dis];
> }
> }
Did you ever Time Profile this? While there are some minor inefficiencies (Why initialise 'dis' and 'collection' on every incremental result? Why initialise suppliedCount every loop iteration?), it's likely that all your time is spent in your distance calculation. While you probably assumed that, I'm having a hard time imagining what it could be doing that would justify it being so slow. A Time Profile might show you something surprising. And/or, you could post your distance algorithm for the list to look over.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden