I did a small benchmark test and found that ObjectOutputStream.writeObject is faster than ObjectOutputStream.write(byte[] bytes) but I can't seem to find a possible explanation as under the hood, writeObject will call ObjectOutputStream.write(byte[] bytes) indirectly
Test code
public static void main(String[] args) throws Exception { byte[] bytes = new byte[10000]; for (int i = 0; i < 10000; ++i) { bytes[i] = (byte) (i % 256); } ByteArrayOutputStream out2 = new ByteArrayOutputStream(); try(ObjectOutputStream ostream2 = new ObjectOutputStream(out2)) { for (int i = 0; i < 10000; ++i) { ostream2.writeInt(bytes.length); ostream2.write(bytes, 0, bytes.length); } out2.reset(); long start = System.nanoTime(); for (int i = 0; i < 10000; ++i) { ostream2.writeInt(bytes.length); ostream2.write(bytes, 0, bytes.length); } long end = System.nanoTime(); System.out.println("write byte[] took: " + ((end - start) / 1000) + " micros"); } ByteArrayOutputStream out = new ByteArrayOutputStream(); try(ObjectOutputStream ostream = new ObjectOutputStream(out)) { for (int i = 0; i < 10000; ++i) { ostream.writeObject(bytes); } out.reset(); long start = System.nanoTime(); for (int i = 0; i < 10000; ++i) { ostream.writeObject(bytes); } long end = System.nanoTime(); System.out.println("writeObject took: " + ((end - start) / 1000) + " micros"); } } Output
write byte[] took: 15445 micros
writeObject took: 3111 micros