Xmlperformance test applicationProgramExtended to compare third-party Libraries
There are many options when talking about iPhone XML parsing. There are two different libraries available in the iPhone SDK, and there are several popular materials, suchTbxml,Touchxml,Kissxml,TinyxmlThird-party libraries andGdataxml. How do Developers choose?
Recently I 've been thinking about various options to find and ultimately extend the apple xmlperformance sample to try out the libraries above, learn how they work, and compare their performance. I think I will share what I 've learned so far by others who may be searching for the best XML library for their iPhone projects.
In this article, we will give a detailed comparison between the features and the performance of the most popular iPhone library, describe how to choose between them, and show a sample project how to read each XML data using the above library.
Dom
Before we start, I want to make sure that the most important difference between everyone is that the XML Parser knows:Whether it is a SAX Parser or a DOM parser.
The SAX Parser is in yourCodeAnalyzer notifications are used to traverse the XML tree. You are using any object that is responsible for maintaining the tracking status and building the data that you may want to parade to keep analyzer tracking.
A's Dom parser reads the entire file and creates a representation in the memory. You can query different elements. In general, you can even build an XPATH query to exit the Special component.
Okay, now let's discuss some libraries!
The most popular XML analyzer is iPhone
In my research, here is the most popular XML Parser for iPhone, and each brief introduction:
NsxmlparserIt is the default iPhone contained in a SAX Parser SDK. This is written in objective-C and is very easy to use, but it may not be so easy because of the DOM model.
Libxml2 is an open source library, including the default use of the iPhone SDK. This is a C-based API, so it is a bit more effort than using nsxml. This library supports both Dom and sax processing. The libxml2 Sax of this processor is particularly cool because it has a unique feature that can parse it and is reading data. For example, you can read a large number of XML documents and display data from the Internet. You are reading it for users, and you are still downloading it.
TbxmlIs a lightweight Dom XML Parser designed as fast as possible, with less memory consumption. It saves verification time and does not support XPath and read-only-you can read its XML, but you cannot modify or write it back.
TouchxmlIt is the iPhone of the nsxml-style Dom XML parser. Like tbxml, it is also read-only, but it does not support XPath like tbxml.
KissxmlIs another nssxml-style Dom XML Parser iPhone, in fact, based on touchxml. The main difference is that kissxml also supports editing, writing, and reading XML.
TinyxmlA small C-dom-based XML Parser header contains only four C files and two. It supports reading and writing XML files at the same time, but it does not support its own XPath. However, you can use the related library-tinyxpath -.
GdataxmlIs another nsxml-style Dom XML Parser for iPhone, Google developer as part of the library, their objective-C client. A short M file is composed of a head. It supports reading and writing XML documents and XPath queries at the same time.
Okay, now let's start comparing all these databases!
Performance Comparison of the XML Parser
Apple has made outstanding code examples to call xmlperformance, allowing you to compare and analyze a ~ kb XML file, among them, the first 300 of iTunes and nsxml libxml2 were both short clips and songs.
This example allows you to select an analysis method, analyze the file, maintain a long time to download the file, and parse the file statistics in the database. Then, you can see a statistics on the screen, average download time and resolution time for each method.
I think this would be an ideal way to test how various APIs interact with each other, so that I expanded the sample to include the aforementioned libraries. You can download the following if you want to try it in your device update project. It can also be used as a good example of how to use the above Api!
Download and update the xmlperformance Project
Description of this project: if the library contains support for xpath, I use a single search for it because I think it represents the way the library will be used in practice. But of course, XPath is generally slower than walking through the tree manually, so it adds benchmarks for these libraries.
So no matter how-I will discuss how to execute the situation with the sample written to my device here, it is the result-but always give it one on your device, or adjust the actual XML data and parse the code lens you need!
Performance Comparison of XML Parser
Below are some figures showing how to quickly parse various parser pairs on my device (1 3G version of the iPhone XML document ):
As you can see here, nsxmlparser is the slowest method so far. Tbxml is the fastest, which makes sense, because many functions are removed to optimize the read-only parsing time.
I was surprised, but seeing that tbxml and some other dom parsing methods are faster than libxml2's SAX Parser, I thought it would be the fastest method. I don't have a special shape, but I guess why it is slow, because it is often necessary to compare the files of the sax Parsing Method in the string.
However, do not view the libxml2 sax method in this discount chart. Keep in mind that libxml2 uses these methods to analyze the file, because it only reads 1-so it allows your program to immediately start displaying data rather than ranking first for downloads.
Okay, here is a chart showing the usage by the parser peak memory (this is obtained by running various methods through the object allocation tool ):
Note that the DOM method usually requires more memory than the sax method and tbxml, which is indeed quite effective (overhead ). This is worth considering when you are processing, especially large files, to get an iPhone memory limit.
In addition, please note that the libxml2's sax method is the best option, because in terms of peak memory usage (I suspect it is larger than others ).
Finally, let's summarize everything between the chart analyzer and the summary. We have discussed the above differences:
-Dom of gdataxmllibxml2-of saxtbxmltouchxmlkissxmltinyxml-of nsxmllibxml2
Included in the SDK? Yes, no, yes
Second time parsing 1.871.190.681.11.371.271.070.84
Peak memory usage 3.113.013.076.55.254.84.154.97
Parse and download? No, yes, no
Edit/save XML? No, no, no, yes
What is XPath support? No, no, no, yes, yes
C or obj-C's c's
License: Apple, MIT, zlib, Apache, MIT
* Tinyxpath =
Which option?
This is the analyzer used by the XML parser. It depends on what analyzer you want to use.
If you only want to read small XML documents, the performance is not important and the files are very small. You may want to use XPath support and something written in objective-C language to make your work easier. Therefore, we recommend that you either use touchxml, kissxml, or gdataxml.
If you want to read and write small XML documents at the same time, the second performance is not important, and the features are rich and easy to use. You may want to write in objective-C when using XPath to support reading/writing. Therefore, we recommend that you use kissxml or gdataxml for this case.
If you want to read a very large XML file, performance is the key issue here. You will consider the DOM of this libxml2 sax, tbxml, or libxml, depending on your specific situation.
So what I did not mention?
Nsxml is a good choice. If you use a relatively small file, you do not think it is like adding a third-party library SDK.
Tinyxml may be a large file determined by the selected API, if you already have experience and a comfortable port for C, as it is easy to move to the iPhone.
I noticed that in this investigation (vtd-XML and target, XML), of course there are two other XML libraries, but I cannot let them work. If others are lucky enough, extend the example project, including them!