Comparison of JAXB XML and JSON Serialization Performance

Once i tried to figure out the difference between JAXB XML and JSON Java Object serialization performance. I wanted to know which one has the better runtime performance and thus scales better. Here are the results!

The test setup is a Windows 7 64bit machine with Intel Core2 Quad Q9450 CPU @2,66GHz. Java Runtime is 1.7.0_07(quite old, i know)

The profiling test case is to serialize and deserialize a simple Java object with JSON and XML. I wanted to run the process 1000, 10000, 100000 and 1000000 times. In contrast i used JSON, XML, Java ObjectOutputStream and Google Kryo. The following table shows the measures:

Type 1000 runs 10000 runs 100000 runs 1000000 runs
Jettison/JSON Marshalling 168ms 863ms 2537ms 16659ms
Jettison/JSON Unmarshalling 136ms 764ms 2229ms 12303ms
SDK JAXB XML Marshalling 109ms 598ms 2019ms 10513ms
SDK JAXB XML Unmarshalling 763ms 5574ms 29958ms 249972ms
SDK ObjectOutputStream Marshalling 71ms 243ms 470ms 1873ms
Google Kryo Marshalling 14ms 85ms 290ms 2557ms

I used Jettison 2.1.3 for the test. Surprisingly it seems that XML marshalling is quite fast, even faster than JSON, but it creates more redundant data! But XML unmarshalling is terribly slow compared to JSON! And it also getting worse under heavy load, probably due to the XML DOM creates a lot of small objects, and this causes heavy garbage collector load. The non human readable serialization like ObjectOutputStream or Google Kryo perform better than JSON or XML at serialization time.

Funny, isn’t it? It you want to know more about Java serialization performance, you can consult

JSON testcase source code:

XML testcase source code:

ObjectOutputStream testcase source code:

Google Kryo testcase source code: