• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Optimizing a loop
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Optimizing a loop
      • From: "Eric E. Dolecki" <email@hidden>
  • Prev by Date: Re: Saving a rotated image
  • Next by Date: Re: Optimizing a loop
  • Previous by thread: Re: Opening a file read-only?
  • Next by thread: Re: Optimizing a loop
  • Index(es):
    • Date
    • Thread