XML in Java: Data binding, part 2nd: Performance

Source: Internet
Author: User
Tags compact

Part 1th describes the background on why you want to use data binding to XML, and also outlines the Java framework that can be used for data binding. If you haven't read the 1th part, you might at least have a look at that article now. In this section, I'll discuss the performance issue directly without further discussion of the reason and the method!

Performance test

To perform a performance test on the data binding framework, I generated a document that contained the simulated flight timetable information. The structure of these documents is the same as the structure I defined in earlier articles about using Castor to map data binding. The following is a sample of the structure, which is called a compact format because it mainly uses attributes for the data:

Listing 1. A compact Document format

<?xml version= "1.0"?>
<timetable>
<carrier ident= "AR" rating= "9" >
<URL>http://www.arcticairlines.com</URL>
<name>arctic airlines</name>
</carrier>
<carrier ident= "CA" rating= "7" >
<URL>http://www.combinedlines.com</URL>
<name>combined airlines</name>
</carrier>
<airport ident= "Sea" >
<location>seattle, wa</location>
<name>seattle-tacoma International
Airport</name>
</airport>
<airport ident= "LAX" >
<location>los Angeles, ca</location>
<name>los Angeles International
Airport</name>
</airport>
<route from= "Sea" to= "LAX" >
<flight carrier= "AR" depart= "6:23a"
Arrive= "8:42a" number= "426"/>
<flight carrier= "CA" depart= "8:10a"
Arrive= "10:52a" number= "833"/>
<flight carrier= "AR" depart= "9:00a"
Arrive= "11:36a" number= "433"/>
</route>
<route from= "LAX" to= "Sea" >
<flight carrier= "CA" depart= "7:45a"
Arrive= "10:20a" number= "311"/>
<flight carrier= "AR" depart= "9:27a"
Arrive= "12:04p" number= "593"/>
<flight carrier= "AR" depart= "12:30p"
Arrive= "3:07p" number= "102"/>
</route>
</timetable>

Note: The airport name information in Listing 1 is usually a line of code. To accommodate the column size, some lines of code are taken apart and appear on two lines.

In addition to the compact format, I tried a variant whose data values used more child elements (only the ID and IDREF continue to use attributes). The following is the same data that is represented in a format called full format here:

Listing 2. Full Document Format

<?xml version= "1.0"?>
<timetable>
<carrier ident= "AR" >
<rating>9</rating>
<URL>http://www.arcticairlines.com</URL>
<name>arctic airlines</name>
</carrier>
<carrier ident= "CA" >
<rating>7</rating>
<URL>http://www.combinedlines.com</URL>
<name>combined airlines</name>
</carrier>
<airport ident= "Sea" >
<location>seattle, wa</location>
<name>seattle-tacoma International airport</name>
</airport>
<airport ident= "LAX" >
<location>los Angeles, ca</location>
<name>los Angeles International airport</name>
</airport>
<route from= "Sea" to= "LAX" >
<flight carrier= "AR" >
<number>426</number>
<depart>6:23a</depart>
<arrive>8:42a</arrive>
</flight>
<flight carrier= "CA" >
<number>833</number>
<depart>8:10a</depart>
<arrive>10:52a</arrive>
</flight>
<flight carrier= "AR" >
<number>433</number>
<depart>9:00a</depart>
<arrive>11:36a</arrive>
</flight>
</route>
<route from= "LAX" to= "Sea" >
<flight carrier= "CA" >
<number>311</number>
<depart>7:45a</depart>
<arrive>10:20a</arrive>
</flight>
<flight carrier= "AR" >
<number>593</number>
<depart>9:27a</depart>
<arrive>12:04p</arrive>
</flight>
<flight carrier= "AR" >
<number>102</number>
<depart>12:30p</depart>
<arrive>3:07p</arrive>
</flight>
</route>
</timetable>

Typically, the relative performance of the XML framework varies greatly depending on the size of the document being used, so in these performance tests, I also include both large and small documents. Large documents (Time-comp.xml and Time-full.xml) use the same data values (represented in two different formats, as shown above). The size is therefore significantly different (in a compact format of 211 KB, and in full format). Small documents are in the collection, each containing 34 documents, the size of the compact format (Ttcomp) varies from 1.4-3.3 KB, and the full format (ttfull) varies from 2.2-5.8 KB. As with large documents, the corresponding documents in the collection of small documents contain the same data values. The complete set of documents used in the test can be obtained from the download page.

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.