Hi Nir, Nir Hauser wrote:
> On the "About" page, it says: > "*Clean XML.* No information is duplicated that can be obtained via > reflection. This results in XML that is easier to read for humans and > *more compact than native Java serialization*." > > Can you provide any data that compares XStream to Java native > Serialization in terms of speed of serialization, deserialization, and > size of data? Hehehe, actually some statements on the HP are older than my involvement into this project. However, as always, the right answer is - it depends. For a short impression I modified the ParserBenchmark (used to create http://xstream.codehaus.org/parser-benchmarks.html) of XStream's benchmark package and get following results: ====================================================================== Size of serialized data ====================================================================== * SingleValue Converters - XStream (XML with SJSXP StAX parser).............. 234.0 bytes - XStream (XML with Xpp3 parser).................... 243.0 bytes - Java object serialization......................... 613.0 bytes * Serializable types - XStream (XML with SJSXP StAX parser).............. 2118.0 bytes - XStream (XML with Xpp3 parser).................... 2391.0 bytes - Java object serialization......................... 497.0 bytes ====================================================================== Deserialization speed (1000 iterations) ====================================================================== * SingleValue Converters - XStream (XML with SJSXP StAX parser).............. 495.0 ms - XStream (XML with Xpp3 parser).................... 531.0 ms - Java object serialization......................... 397.0 ms * Serializable types - XStream (XML with SJSXP StAX parser).............. 473.0 ms - XStream (XML with Xpp3 parser).................... 265.0 ms - Java object serialization......................... 70.0 ms As you can see, there are cases where XStream is better in size. As a rule of thumb you can say that with increasing complexity of the objects the size increases faster. Actually I expect for the typical use case with no special setup, that the XML takes more bytes ;-) However, effectively it depends on your use case and setup of XStream. By default XStream will often use class names in the XML representation. Using aliases for those classes can decrease the XML size significantly. You may additionally use in some cases custom converters instead the default ones of XStream. Especially serializable classes that are handled by the fallback SerailizableConverter tend to increase the XML structure. Concerning speed, it largely depends on the underlaying XML parser and again on your setup (e.g. using custom converters again). Therefore, if you have requirements on size and speed, you will have to measure and tweak this on your own for your special use case. Regards, Jörg BTW: Here's the diff for ParserBenchmark to generate the posted results: =================== %< ===================== ~/src/Codehaus/xstream/xstream-benchmark $ svndiff Index: src/test/com/thoughtworks/xstream/tools/benchmark/parsers/ParserBenchmark.java =================================================================== --- src/test/com/thoughtworks/xstream/tools/benchmark/parsers/ParserBenchmark.java (revision 1973) +++ src/test/com/thoughtworks/xstream/tools/benchmark/parsers/ParserBenchmark.java (working copy) @@ -13,6 +13,8 @@ import com.thoughtworks.xstream.core.JVM; import com.thoughtworks.xstream.tools.benchmark.Harness; import com.thoughtworks.xstream.tools.benchmark.metrics.DeserializationSpeedMetric; +import com.thoughtworks.xstream.tools.benchmark.metrics.SizeMetric; +import com.thoughtworks.xstream.tools.benchmark.products.JavaObjectSerialization; import com.thoughtworks.xstream.tools.benchmark.products.XStreamDom; import com.thoughtworks.xstream.tools.benchmark.products.XStreamDom4J; import com.thoughtworks.xstream.tools.benchmark.products.XStreamBEAStax; @@ -71,39 +73,42 @@ if (commandLine.hasOption('p')) { name = commandLine.getOptionValue('p'); } - if (name == null || name.equals("DOM")) { - harness.addProduct(new XStreamDom()); - } - if (name == null || name.equals("JDOM")) { - harness.addProduct(new XStreamJDom()); - } - if (name == null || name.equals("DOM4J")) { - harness.addProduct(new XStreamDom4J()); - } - if (name == null || name.equals("XOM")) { - harness.addProduct(new XStreamXom()); - } - if (name == null || name.equals("BEAStAX")) { - harness.addProduct(new XStreamBEAStax()); - } - if (name == null || name.equals("Woodstox")) { - harness.addProduct(new XStreamWoodstox()); - } +// if (name == null || name.equals("DOM")) { +// harness.addProduct(new XStreamDom()); +// } +// if (name == null || name.equals("JDOM")) { +// harness.addProduct(new XStreamJDom()); +// } +// if (name == null || name.equals("DOM4J")) { +// harness.addProduct(new XStreamDom4J()); +// } +// if (name == null || name.equals("XOM")) { +// harness.addProduct(new XStreamXom()); +// } +// if (name == null || name.equals("BEAStAX")) { +// harness.addProduct(new XStreamBEAStax()); +// } +// if (name == null || name.equals("Woodstox")) { +// harness.addProduct(new XStreamWoodstox()); +// } if (JVM.is16() && (name == null || name.equals("SJSXP"))) { harness.addProduct(new XStreamSjsxp()); } if (name == null || name.equals("Xpp3")) { harness.addProduct(new XStreamXpp3()); } - if (name == null || name.equals("kXML2")) { - harness.addProduct(new XStreamKXml2()); +// if (name == null || name.equals("kXML2")) { +// harness.addProduct(new XStreamKXml2()); +// } +// if (name == null || name.equals("Xpp3DOM")) { +// harness.addProduct(new XStreamXpp3DOM()); +// } +// if (name == null || name.equals("kXML2DOM")) { +// harness.addProduct(new XStreamKXml2DOM()); +// } + if (name == null || name.equals("Java")) { + harness.addProduct(new JavaObjectSerialization()); } - if (name == null || name.equals("Xpp3DOM")) { - harness.addProduct(new XStreamXpp3DOM()); - } - if (name == null || name.equals("kXML2DOM")) { - harness.addProduct(new XStreamKXml2DOM()); - } if (commandLine.hasOption('n')) { counter = Integer.parseInt(commandLine.getOptionValue('n')); } @@ -111,18 +116,17 @@ e.printStackTrace(); } + harness.addMetric(new SizeMetric()); harness.addMetric(new DeserializationSpeedMetric(counter, false)); harness.addTarget(new BasicTarget()); - harness.addTarget(new ExtendedTarget()); - harness.addTarget(new ReflectionTarget()); +// harness.addTarget(new ExtendedTarget()); +// harness.addTarget(new ReflectionTarget()); harness.addTarget(new SerializableTarget()); - harness.addTarget(new JavaBeanTarget()); - if (false) { - harness.addTarget(new FieldReflection()); - harness.addTarget(new HierarchyLevelReflection()); - harness.addTarget(new InnerClassesReflection()); - harness.addTarget(new StaticInnerClassesReflection()); - } +// harness.addTarget(new JavaBeanTarget()); +// harness.addTarget(new FieldReflection()); +// harness.addTarget(new HierarchyLevelReflection()); +// harness.addTarget(new InnerClassesReflection()); +// harness.addTarget(new StaticInnerClassesReflection()); harness.run(new TextReporter(new PrintWriter(System.out, true))); System.out.println("Done."); } =================== %< ===================== --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
