Re: Home-brewed code is 100X faster than -[NSScanner scanDecimal:] ??
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