• 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: Home-brewed code is 100X faster than -[NSScanner scanDecimal:] ??
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Home-brewed code is 100X faster than -[NSScanner scanDecimal:] ??


  • Subject: Re: Home-brewed code is 100X faster than -[NSScanner scanDecimal:] ??
  • From: glenn andreas <email@hidden>
  • Date: Thu, 03 Feb 2011 15:57:55 -0600

On Feb 3, 2011, at 3:05 PM, Jerry Krinock wrote:

> Thanks, Glenn, and thanks, Matt, for the explanation.
>
> So I added a parameter to my method which one can use to get the performance improvement only if they are willing to compromise accuracy and parsing of numbers written in "e" notation.  Also, I chose a name which is less likely to used by Apple.
>

Why not just use NSScanner's scanDouble: instead of trying to scan a string that you think is valid and then convert to a double?

For example, if the input string is @"123.45-67.89" you'll end up scanning the entire string (which scanDecimal: or scanDouble: will only scan up through the "5").

Using scanDouble: will give you back support for scientific notation and consistent handling of "unexpected" strings, and all the other subtleness that can occur with floating point parsing (for example, you're code also misses handling things like "+123")

Glenn Andreas                      email@hidden
The most merciful thing in the world ... is the inability of the human mind to correlate all its contents - HPL

_______________________________________________

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: Home-brewed code is 100X faster than -[NSScanner scanDecimal:] ??
      • From: Jerry Krinock <email@hidden>
References: 
 >Home-brewed code is 100X faster than -[NSScanner scanDecimal:] ?? (From: Jerry Krinock <email@hidden>)
 >Re: Home-brewed code is 100X faster than -[NSScanner scanDecimal:] ?? (From: glenn andreas <email@hidden>)
 >Re: Home-brewed code is 100X faster than -[NSScanner scanDecimal:] ?? (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: origin: lower left vs lower right
  • Next by Date: NSTextView line wrap toggle (was NSTextView exception with line wrap and horizontal scroller - RESOLVED)
  • Previous by thread: Re: Home-brewed code is 100X faster than -[NSScanner scanDecimal:] ??
  • Next by thread: Re: Home-brewed code is 100X faster than -[NSScanner scanDecimal:] ??
  • Index(es):
    • Date
    • Thread