Re: Optimizing a loop
Re: Optimizing a loop
- Subject: Re: Optimizing a loop
- From: "Eric E. Dolecki" <email@hidden>
- Date: Wed, 10 Aug 2011 11:40:47 -0400
Thanks for the reply. I've since broken up the songs into buckets depending
on the title length and I use a Dictionary to retrieve arrays based on the
length, then I am only searching a subset. It's WAY faster than searching
the entire collection of songs. I just pre-build this during app start up so
I only take the building hit once up front. Takes under 1 second to perform
the searching.
Google Voice: (508) 656-0622
Twitter: eric_dolecki XBoxLive: edolecki PSN: eric_dolecki
http://blog.ericd.net
On Wed, Aug 10, 2011 at 11:27 AM, Wade Tregaskis <email@hidden> wrote:
> > //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