libxml2 will always be faster than NSXMLParser for many reasons, however, it is up to you, which is more useful for your project.
NSXMLParser is generally prettier. The code makes sense, since there should be a sax parser, and this is a real Cocoa class with all conventions. If usability and clean code are your top priorities, you should stick with NSXMLParser.
While NSXMLParser uses libxml2 on the backend, it is slower due to the bases of Objective-C and the Achilles heel of Objective-C. When parsing XML, you basically just do a bunch of hard loops over and over again to find the tags you are interested in.
This is the lesson - when you cannot use Fast Object Enumeration in a narrow Objective-C loop, you are looking at a serious performance hit. Submission / Delegation responds to the Selector / and other Objective-C base language constructors, which gives you a real flaw.
I'm not going to enter the newsletter, but the bottom line is that when you access something like this: "[zomg lolz]" you pass the method signature to the Objective-C dispatcher to find the target C function for your Objective-C signature . This search process, when performed over and over again, can significantly reduce performance.
If you're on an iPhone, go libxml2 and don't look back - but if your target machine has two processors and more than god, I would go NSXMLParser to simplify code maintenance.
Alex C Schaefer May 16 '09 at 4:46 a.m. 2009-05-16 04:46
source share