Speed of NSScanner vs NSXMLParser?
I have 开发者_StackOverflowan iPhone App that reads in an XML file, then pulls out the necessary data by looping through an NSScanner. The XML is not particularly long.
I am wondering if it would be worth the work to implement NSXMLParser in place of using NSScanner, if I will see any real improvement in speed?
There's a nice comparison article for different XML parsers:
http://www.raywenderlich.com/553/how-to-chose-the-best-xml-parser-for-your-iphone-project
The guy uses 900kb (!!!) XML file as a test sample, and the results are quite interesting: NSXMLParser is by far the slowest. That said, I think NSXMLParser on it's own uses NSScanner (or similar) + extra processing for bells and whistles related to XML.
If your solution works fine and is easy to maintain, I would not switch to any specialized parser. However if you are planning to extend your XML usage, it's probably a good idea to start using one.
If you want to directly test how fast each approach is, there is an open source tool called CodeTimestamps that may be helpful:
http://eng.pulse.me/line-by-line-speed-analysis-for-ios-apps/
精彩评论