Tag Archives: nio

Performance of various methods of binary serialization in Java

by Mikhail Vorontsov

We are going to find out what is the performance of binary serialization in Java. Following classes will be compared:

  • DataInputStream(ByteArrayInputStream) and its counterpart DataOutputStream(ByteArrayOutputStream)
  • See how synchronization affects ByteArrayInput/OutputStream and check performance of BAInputStream – copy of ByteArrayInputStream w/o synchronization
  • ByteBuffer in its 4 flavours – heap/direct, big/little endian
  • sun.misc.Unsafe – based memory operations on heap byte arrays

My experience has shown me that all these serialization methods depend on on data item size as well as on buffer/stream type. So, two sets of tests were written. First test works on an object having a single field – byte[500], while second test is using another object with another single field – long[500]. In case of ByteBuffer and Unsafe we will test both bulk operations and serialization of every array element as a separate method call.

Continue reading