Benchmarks between XmlWriter and competitors

  • All times are in milliseconds.
  • "***" means an out of memory exception was generated.
  • See notes below for further details.
Records Written XmlWriter 1.0 J2EE 1.3 JDOM 1.0 Beta 8 NanoXML/Lite 2.2.1 ECS 1.4.1
5,0004911,2621,4731,82281,017
10,0008212,1032,4343,345350,805
15,0001,0513,7153,144******
20,0001,4423,8864,416
25,0001,6426,3396,059
30,0001,853******
35,0002,063
40,0002,654
45,0002,854
50,0003,044
55,0003,245
60,0003,445
65,0003,645
70,0003,846
75,0004,026
80,000***

Notes

  1. All benchmarks were run on a 1.2 GHz Athlon with 512 MB of memory, under Windows XP. No other apps were running, though there are always drivers, a desktop, etc. running in Windows.
  2. Benchmarks were run 3 times, and the fastest score recorded. There wasn't much variation between runs anyway, but the fastest score seems best since this probably has the least background noise from multitasking, etc.
  3. The benchmark test writes multiple copies of a short XML fragment to a StringWriter. By using a StringWriter, an out of memory exception is guaranteed when the number of records gets sufficiently large. So this benchmark gauges memory efficiency as well as speed.
  4. "Pretty printing" was enabled for all benchmarks. However, only XmlWriter and JDOM implement pretty printing in a meaningful way. The other libraries insert far less white space, skewing results in their favor.
  5. The benchmark writes an XML document of the following form:

    <?xml version="1.0" encoding="UTF-8"?>

    <object_list>

    <!-- Object number 1 -->

    <object number="1">

    <attribute_only attr="value"/>

    <nested1 nesting_level="1">

    <nested2 nesting_level="2">Some text</nested2>

    </nested1>

    <more_text>Some more text</more_text>

    </object>

    <!-- Object number 2 -->

    ...

    </object_list>

Source code

Available from cvs.

Todo

We need to benchmark outputting with SAX [probably fast but very very ugly] and to compare against Xml-enc. Xmlenc will be faster but has less features.