Codebase list libxstream-java / db725b78-e06f-4bbe-9729-33eea41d84e7/main xstream-distribution / src / content / benchmarks.html
db725b78-e06f-4bbe-9729-33eea41d84e7/main

Tree @db725b78-e06f-4bbe-9729-33eea41d84e7/main (Download .tar.gz)

benchmarks.html @db725b78-e06f-4bbe-9729-33eea41d84e7/mainraw · history · blame

<html>
<!--
 Copyright (C) 2015, 2016, 2017, 2018, 2020, 2021 XStream committers.
 All rights reserved.
 
 The software in this package is published under the terms of the BSD
 style license a copy of which has been included with this distribution in
 the LICENSE.txt file.
 
 Created on 10. December 2015 by Joerg Schaible
 -->
  <head>
    <title>Benchmarks</title>
        <style type="text/css">
            #content td { text-align: right;}
            #content dt { font-weight: bold;}
        </style>
  </head>

  <body>
    <h2 id="introduction">Introduction</h2>

    <p>Benchmark results are always dependent on a very individual setup.  Normally it is not useful to generalize such results
    for every use case, but it can give you a hint.  However, if you're really in the need of maximum performance, you should
    probably create an own benchmark with your objects or even use a profiler to detect the real hot spots in your application.</p>

	<p>XStream uses the Java Microbenchmark Harness (<a href="http://openjdk.java.net/projects/code-tools/jmh/">JMH</a>)
	of the JDK Tools as benchmark framework starting with version 1.4.9. As result it contains a ZIP file
	(xstream-jmh-&lt;version&gt;-app.zip) as new artifact containing anything required to run the benchmarks.  Unpack the file
	and use the scripts in the <em>bin</em> directory to execute the benchmarks.  Use option -h to look at the options provided
	by JMH.  You may exchange the libraries in the <em>lib</em> directory with other versions of XStream or the individual
	parsers or you may even add new JMH benchmarks to the default ones of XStream.</p>
	
	<p>All benchmark values below measure the average throughput in nanosecond per operation.  JMH provides additional
	measurement options, see online help.  The maximum deviation for each benchmark is recorded in the reference files of the
	distributed ZIP file.  The benchmark is executed on Linux 5.4.48 Gentoo 64-bit system with an Intel Core i7 CPU 920 of 2.67
	GHz using OpenJDK 11.0.8.  Note again, that these values are no replacement for real profiler results and they may vary
	from run to run (see reference files) due to this machine's background processes. However, it can give you some idea of
	what you can expect using different parser technologies.</p>
	
    <h2 id="parser">Parser Benchmark</h2>
	
	<p>The values represent the average throughput of 15 runs with a single thread. The benchmarks emphasis the parser
	efficiency for different structures.</p>
	
    <table summary="Benchmark for all parsers supported by XStream using different object structures">
      <tr>
        <th>Parser</th>
        <th>Text</th>
        <th>Array</th>
        <th>Nested</th>
      </tr>
      <tr>
        <th>W3C DOM (Open JDK 11.0.8)</th>
        <td>10568442.558</td>
        <td>59894584.643</td>
        <td>5382390.375</td>
      </tr>
      <tr>
        <th>JDOM (1.1.3)</th>
        <td>6379300.940</td>
        <td>6887733.303</td>
        <td>13598531.633</td>
      </tr>
      <tr>
        <th>JDOM 2 (2.0.5)</th>
        <td>5929805.928</td>
        <td>9876176.832</td>
        <td>12503949.903</td>
      </tr>
      <tr>
        <th>DOM4J (1.6.1)</th>
        <td>8543670.534</td>
        <td>79125701.566</td>
        <td>5372787.809</td>
      </tr>
      <tr>
        <th>XOM (1.1)</th>
        <td>7968868.873</td>
        <td>34141742.595</td>
        <td>5425911.128</td>
      </tr>
      <tr>
        <th>StAX (BEA 1.2.0)</th>
        <td>3182516.188</td>
        <td>667706.032</td>
        <td>603986.803</td>
      </tr>
      <tr>
        <th>StAX (Woodstox 3.2.7)</th>
        <td>1959085.951</td>
        <td>630843.461</td>
        <td>835465.393</td>
      </tr>
      <tr>
        <th>StAX (Open JDK 11.0.8)</th>
        <td>8450930.541</td>
        <td>885917.070</td>
        <td>868883.676</td>
      </tr>
      <tr>
        <th>XPP (MXParser 1.2.1)</th>
        <td>2131602.489</td>
        <td>814691.675</td>
        <td>13287597.794</td>
      </tr>
      <tr>
        <th>XPP (Xpp3 min 1.1.4c)</th>
        <td>2084284.951</td>
        <td>754593.348</td>
        <td>13056389.184</td>
      </tr>
      <tr>
        <th>XPP (kXML2 min 2.3.0)</th>
        <td>3561706.234</td>
        <td>855787.083</td>
        <td>36819091.742</td>
      </tr>
      <tr>
        <th>Binary (XStream 1.4.16)</th>
        <td>1065228.134</td>
        <td>405493.660</td>
        <td>284620.649</td>
      </tr>
      <tr>
        <th>Jettison (1.2)</th>
        <td>3682704.689</td>
        <td>601803.834</td>
        <td>678187.271</td>
      </tr>
    </table>
  
    <dl>
      <dt>Text</dt>
      <dd>A single element with a text of 100.000 characters.</dd>
      <dt>Array</dt>
      <dd>A single element with 1.000 child elements.</dd>
      <dt>Nested</dt>
      <dd>Nested elements in 1000 levels (since version 1.4.10).</dd>
    </dl>
	
    <h2 id="converterType">Converter Type Benchmark</h2>

	<p>The values represent the average throughput of 16 runs with four threads using the Xpp3 parser for a structure
	with 1.000 elements. The benchmarks demonstrate the different converter types that can be used for a standard Java
	class.</p>
	
    <table summary="Benchmark for different converter types of XStream">
      <tr>
        <th>Converter Type</th>
        <th>Throughput</th>
      </tr>
      <tr>
        <th>Custom</th>
        <td>9324531.713</td>
      </tr>
      <tr>
        <th>Java Bean</th>
        <td>19658157.449</td>
      </tr>
      <tr>
        <th>Reflection</th>
        <td>20859870.075</td>
      </tr>
    </table>
  
    <dl>
      <dt>Custom</dt>
      <dd>A converter especially written for the Java type to convert.</dd>
      <dt>Java Bean</dt>
      <dd>Usage of the generic JavaBeanConverter, since the Java type respects the Java Bean contract.</dd>
      <dt>Reflection</dt>
      <dd>Usage of the generic converter based on reflection.</dd>
    </dl>
	
    <h2 id="stringConverter">String Converter Benchmark</h2>

	<p>The values represent the average throughput of 16 runs with four threads using the Xpp3 parser for a structure
	with 10.000 string elements of various sizes and duplicates. The benchmarks demonstrate different implementations
	and configurations of the StringConverter.</p>
	
    <table summary="Benchmark for different StringConverter strategies">
      <tr>
        <th>StringConverter Strategy</th>
        <th>Throughput</th>
      </tr>
      <tr>
        <th>No Cache</th>
        <td>9796296.611</td>
      </tr>
      <tr>
        <th>Intern</th>
        <td>14262839.973</td>
      </tr>
      <tr>
        <th>ConcurrentMap (length limit)</th>
        <td>10538757.220</td>
      </tr>
      <tr>
        <th>ConcurrentMap (unlimited)</th>
        <td>11252298.498</td>
      </tr>
      <tr>
        <th>Sync'd WeakCache (length limit)</th>
        <td>11298773.753</td>
      </tr>
      <tr>
        <th>Sync'd WeakCache (unlimited)</th>
        <td>11279714.685</td>
      </tr>
    </table>
  
    <dl>
      <dt>No Cache</dt>
      <dd>An implementation that does not cache deserialized String values with the consequence that repeated values
      will always allocate separate memory.</dd>
      <dt>Intern</dt>
      <dd>An implementation that uses String.intern() to cache the individual values. The memory pool used for the
      values is dependent on the JDK version. Up to Java 7 this was the permanent generation space i.e. the memory has
      to be shared with all loaded classes. It is up to the garbage collection when these string values are freed
      again.</dd>
      <dt>ConcurrentMap (length limit)</dt>
      <dd>An implementation that uses a ConcurrentHashMap as cache for strings of limited length (38 characters). The
      lifetime of the cache is equivalent with the lifetime of the XStream instance.</dd>
      <dt>ConcurrentMap (unlimited)</dt>
      <dd>An implementation that uses a ConcurrentHashMap as cache for all strings. The lifetime of the cache is
      equivalent with the lifetime of the XStream instance.</dd>
      <dt>Sync'd WeakCache (length limit)</dt>
      <dd>An implementation that uses a WeakCache for strings of limited length (38 characters). This cache uses weak 
      references for its keys and values. An entry is therefore only kept as long as the deserialized object structure
      is referencing it. This is XStream's default strategy.</dd>
      <dt>Syn'd WeakCache (unlimited)</dt>
      <dd>An implementation that uses a WeakCache for all strings. This cache uses weak references for its keys and
      values. An entry is therefore ony kept as long as the deserialized object structure is referencing it.</dd>
    </dl>
	
    <h2 id="nameCoder">Name Coder Benchmark</h2>

	<p>The values represent the average throughput of 25 runs with four threads using the Xpp3 parser for a structure
	with 250 nested elements using names invalid for XML elements. The benchmarks demonstrate different implementation
	strategies for a NameCoder to create valid tag names in XML.</p>
	
    <table summary="Benchmark for different NameCoder strategies">
      <tr>
        <th>NameCoder Implementation</th>
        <th>Throughput</th>
      </tr>
      <tr>
        <th>No Coding</th>
        <td>3917564.563</td>
      </tr>
      <tr>
        <th>Dollar Coding</th>
        <td>4570684.356</td>
      </tr>
      <tr>
        <th>Escaped Underscore Coding</th>
        <td>6322642.927</td>
      </tr>
      <tr>
        <th>Cached Escaped Underscore Coding</th>
        <td>4339193.305</td>
      </tr>
      <tr>
        <th>XML Friendly Coding</th>
        <td>5102368.550</td>
      </tr>
    </table>
  
    <dl>
      <dt>No Coding</dt>
      <dd>An implementation that does not encode the names of XML elements. It relies on the fact that the object graph
      does not contain elements with invalid XML names, because the name of the class types and members are either
      conforming or have been aliased.</dd>
      <dt>Dollar Coding</dt>
      <dd>An implementation that uses String.replace to replace any dollar sign with '&#xb7;' (middle dot), a valid
      character normally not used for Java identifiers. In typical Java code there are no other invalid characters used
      for Java identifiers, however, Java allows identifiers to contain a wide range of UTF-8 characters and the JVM
      has even less restrictions.</dd>
      <dt>Escaped Underscore Coding</dt>
      <dd>An implementation that uses a StringBuilder to create the XML name by replacing any dollar sign with '_-' and
      escapes every plain underscore with two ones. The implementation will therefore only use characters in the
      standard ASCII range. It is not possible to use a simple minus sign as replacement because it is not a valid
      first character for XML names. However, the comments about Java identifiers and JVM identifiers from the Dollar
      Coding still apply.</dd>
      <dt>Cached Escaped Underscore Coding</dt>
      <dd>An implementation that implements a cache for the NameCoder that escapes the underscores.</dd>
      <dt>XML Friendly Coding</dt>
      <dd>The default implementation of XStream using a StringBuilder and a cache, encoding any character that is
      invalid for XML names. It implements also the underscore escaping for compatibility reasons with XML created by
      earlier versions of XStream.</dd>
    </dl>
  </body>
</html>