is jdom really slower than dom4j?

Source: Internet
Author: User
Tags xml parser
Dom
Some XML parser users think JDOM is slow, at least not as efficient as dom4j. In fact, Jdom and dom4j, the same outstanding open source XML parser, there is no need to worry so. Now actually take some examples of actual use, as a simple test case, to Jdom and dom4j the most basic document parsing function to illustrate this problem. Jdom test cases are as follows:
Public Document Getdoc (String filename) throws IOException, jdomexception {saxbuilder sb = new Saxbuilder ();

Saxbuilder sb = new Saxbuilder ("Org.apache.crimson.parser.XMLReaderImpl");          Document doc = null; Passed is the file path when doc = Sb.build (new FileInputStream (filename));

return doc; }

DOM4J test cases are as follows
Public Document Getdoc (String filename) throws FileNotFoundException, documentexception {saxreader sb = new Saxrea Der ();

Document doc = null;

Passed is the file path when doc = Sb.read (new FileInputStream (filename));

return doc; }

Test platform Environment: Intel 1.4G Centrino 768MB, winXp Pro SP2, JDK 1.4.2 jdom version 1.0rc1dom4j version 1.5.2



Public Document Getdoc (String filename) throws IOException, jdomexception {saxbuilder sb = new Saxbuilder ();

Saxbuilder sb = new Saxbuilder ("Org.apache.crimson.parser.XMLReaderImpl");          Document doc = null; Passed is the file path when doc = Sb.build (new FileInputStream (filename));

return doc; }

DOM4J test cases are as follows
Public Document Getdoc (String filename) throws FileNotFoundException, documentexception {saxreader sb = new Saxrea Der ();

Document doc = null;

Passed is the file path when doc = Sb.read (new FileInputStream (filename));

return doc; }

Test platform Environment: Intel 1.4G Centrino 768MB, winXp Pro SP2, JDK 1.4.2 jdom version 1.0rc1dom4j version 1.5.2


Public Document Getdoc (String filename) throws FileNotFoundException, documentexception {saxreader sb = new Saxrea Der ();

Document doc = null;

Passed is the file path when doc = Sb.read (new FileInputStream (filename));

return doc; }

Test platform Environment: Intel 1.4G Centrino 768MB, winXp Pro SP2, JDK 1.4.2 jdom version 1.0rc1dom4j version 1.5.2

Neither of the SAX parser classes is specified, and the document tree structure is obtained using the Sax event method

Test documents as you see the document at the end of the layer structure XML document.

Each test case set 200 times to 5 groups at the same time, see the overall resolution speed jdom6.93s 6.94s 6.96s 7.05s 7sdom4j7.551s 7.581s 7.631s 7.55s 7.621s

As a result, the jdom and dom4j parsing speeds are the same, and there may be slightly different document speeds, and when the Jdom XML sax parser is replaced by Org.apache.crimson.parser.XMLReaderImpl, Speed will be increased by about 0.5s, and dom4j to improve the 0.2s. In addition, I also to multiple structure of XML document parsing, more than 20,000 lines of XML document parsing, did not find jdom resolution than dom4j slow, the speed is basically 55 points. Some jdom fast, some dom4j fast, interested readers can do their own experiments.

About some in the resolution of the slow speed, there are memory overflow, I think it is due to other reasons, or traversal of the writing problem. Therefore, whether using dom4j or jdom can follow their favorite hobby use, there is no need to worry about the so-called speed problem.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.