Cryo vs Jackson

I am checking Java Serialization, Kryo and Jackson.

I created a little tiny code that serializes random objects N times. I am measuring the time to serialize and deserialize and the size of an object.

I am not very happy with the size of Kryo vs Jackson, I read about benchmarks and people had a big difference between Kryo and Jackson, but I only have 5-10% less in Kryo. I don't know if I missed something in my code.

This is my code for Kryo:

public static byte[] writeAsBytes(final Object oObject) {

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        Output output = new Output(bos);
        kryo2.register(Event.class, 0);
        kryo2.writeClassAndObject(output, oObject);
        output.close();
        return bos.toByteArray();
    }


    public static <T> T read(final byte[] aObject, final Class<T> clazz) {
        T oObject;
        ByteArrayInputStream is = new ByteArrayInputStream(aObject);
        Input input = new Input(is);
        kryo2.register(clazz, 0);
        oObject = (T) kryo2.readClassAndObject(input);
        input.close();

        return oObject;
    }

      

I tried registering objects and without registering, I had the same size and the timing was similar.

How can I improve the size with Kryo ?? Size and time I got:

Size java:5245
Size jackson:5076
Size kryo:4790
14/09/22 12:18:05 INFO util.TimerUtil: DesSerializar Jackson:25135ms,Counter:10001
14/09/22 12:18:05 INFO util.TimerUtil: DesSerializar Java:2637ms,Counter:10001
14/09/22 12:18:05 INFO util.TimerUtil: DesSerializar Kryo:396ms,Counter:10001
14/09/22 12:18:05 INFO util.TimerUtil: Serializar Jackson:985ms,Counter:10001
14/09/22 12:18:05 INFO util.TimerUtil: Serializar Java:1171ms,Counter:10001
14/09/22 12:18:05 INFO util.TimerUtil: Serializar Kryo:397ms,Counter:10001

      

I execute the code many times and I wonder about the deserialization time for Jackson, 25000ms

+3


source to share


1 answer


Try using kryo.readObject(arg0, arg1)

instead kryo.readClassAndObject(input);

, it serializes objects more efficiently in Java.



0


source







All Articles