Skip to content

Instantly share code, notes, and snippets.

@theotherian
Last active January 1, 2016 04:29
Show Gist options
  • Save theotherian/8092057 to your computer and use it in GitHub Desktop.
Save theotherian/8092057 to your computer and use it in GitHub Desktop.
A serialization shootout
Car
|- String name
|- String description
|- String article
|- int numberOfSeats
|- int numberOfDoors
|- Color color
|- WHITE
|- BLACK
|- GREEN
|- RED
|- BLUE
|- SILVER
|- long timestamp
|- Drivetrain drivetrain
|- Transmission transmission
|- int numberOfGears
|- boolean automatic
|- List<Differential> differentials
|- boolean limitedSlip
|- Engine engine
|- int numberOfCylinders
|- FuelType fuelType
|- GAS
|- DIESEL
|- ELECTRIC
final ObjectMapper mapper = new ObjectMapper();
Harness harness = new Harness(new IORunner() {
@Override
public void serializeDeserialize(Car car) throws Exception {
byte[] carBytes = mapper.writeValueAsBytes(car);
Car output = mapper.readValue(carBytes, Car.class);
}
});
final Kryo kryo = new Kryo();
Harness harness = new Harness(new IORunner() {
@Override
public void serializeDeserialize(Car car) throws Exception {
final Output output = new Output();
final Input input = new Input();
output.setBuffer(new byte[10000]);
kryo.writeObject(output, car);
input.setBuffer(output.getBuffer());
Car read = kryo.readObject(input, Car.class);
}
});
-------------------------------------------------------
[Smile] Number of executions: 10
[Smile] Batch size per execution: 100000
[Smile] Average time in millis: 1886ms
[Smile] Initial execution time: 1832ms
[Smile] Average time in millis (excluding first): 1892ms
[Smile] Average time in nanos per batch: 18860ns
[Smile] Average serialized data size: 5223 bytes
[Smile] Average marshaling time in nanos (per operation): 7699ns
[Smile] Average unmarshaling time in nanos(per operation): 11057ns
-------------------------------------------------------
-------------------------------------------------------
[Kryo] Number of executions: 10
[Kryo] Batch size per execution: 100000
[Kryo] Average time in millis: 1239ms
[Kryo] Initial execution time: 1337ms
[Kryo] Average time in millis (excluding first): 1228ms
[Kryo] Average time in nanos per batch: 12396ns
[Kryo] Average serialized data size: 5233 bytes
[Kryo] Average marshaling time in nanos (per operation): 4244ns
[Kryo] Average unmarshaling time in nanos(per operation): 6786ns
-------------------------------------------------------
-------------------------------------------------------
[JSON] Number of executions: 10
[JSON] Batch size per execution: 100000
[JSON] Average time in millis: 1912ms
[JSON] Initial execution time: 2025ms
[JSON] Average time in millis (excluding first): 1899ms
[JSON] Average time in nanos per batch: 19123ns
[JSON] Average serialized data size: 5295 bytes
[JSON] Average marshaling time in nanos (per operation): 9540ns
[JSON] Average unmarshaling time in nanos(per operation): 9475ns
-------------------------------------------------------
-------------------------------------------------------
[Smile JAXRS] Number of executions: 10
[Smile JAXRS] Batch size per execution: 100000
[Smile JAXRS] Average time in millis: 2588ms
[Smile JAXRS] Initial execution time: 2682ms
[Smile JAXRS] Average time in millis (excluding first): 2577ms
[Smile JAXRS] Average time in nanos per batch: 25881ns
[Smile JAXRS] Average serialized data size: 5223 bytes
[Smile JAXRS] Average marshaling time in nanos (per operation): 8000ns
[Smile JAXRS] Average unmarshaling time in nanos(per operation): 16877ns
-------------------------------------------------------
-------------------------------------------------------
[Smile] Number of executions: 10
[Smile] Batch size per execution: 100000
[Smile] Average time in millis: 623ms
[Smile] Initial execution time: 755ms
[Smile] Average time in millis (excluding first): 609ms
[Smile] Average time in nanos per batch: 6237ns
[Smile] Average serialized data size: 285 bytes
[Smile] Average marshaling time in nanos (per operation): 2771ns
[Smile] Average unmarshaling time in nanos(per operation): 3365ns
-------------------------------------------------------
-------------------------------------------------------
[Kryo] Number of executions: 10
[Kryo] Batch size per execution: 100000
[Kryo] Average time in millis: 574ms
[Kryo] Initial execution time: 752ms
[Kryo] Average time in millis (excluding first): 554ms
[Kryo] Average time in nanos per batch: 5744ns
[Kryo] Average serialized data size: 294 bytes
[Kryo] Average marshaling time in nanos (per operation): 1966ns
[Kryo] Average unmarshaling time in nanos(per operation): 2008ns
-------------------------------------------------------
-------------------------------------------------------
[JSON] Number of executions: 10
[JSON] Batch size per execution: 100000
[JSON] Average time in millis: 686ms
[JSON] Initial execution time: 775ms
[JSON] Average time in millis (excluding first): 676ms
[JSON] Average time in nanos per batch: 6864ns
[JSON] Average serialized data size: 360 bytes
[JSON] Average marshaling time in nanos (per operation): 2809ns
[JSON] Average unmarshaling time in nanos(per operation): 3953ns
-------------------------------------------------------
-------------------------------------------------------
[Smile JAXRS] Number of executions: 10
[Smile JAXRS] Batch size per execution: 100000
[Smile JAXRS] Average time in millis: 875ms
[Smile JAXRS] Initial execution time: 934ms
[Smile JAXRS] Average time in millis (excluding first): 868ms
[Smile JAXRS] Average time in nanos per batch: 8750ns
[Smile JAXRS] Average serialized data size: 285 bytes
[Smile JAXRS] Average marshaling time in nanos (per operation): 2472ns
[Smile JAXRS] Average unmarshaling time in nanos(per operation): 6012ns
-------------------------------------------------------
final ObjectMapper mapper = new ObjectMapper(new SmileFactory());
Harness harness = new Harness(new IORunner() {
@Override
public void serializeDeserialize(Car car) throws Exception {
byte[] carBytes = mapper.writeValueAsBytes(car);
Car output = mapper.readValue(carBytes, Car.class);
}
});
final JacksonSmileProvider provider = new JacksonSmileProvider();
Harness harness = new Harness(new IORunner() {
@Override
public void serializeDeserialize(Car car) throws Exception {
ByteArrayOutputStream output = new ByteArrayOutputStream();
provider.writeTo(car, Car.class, null, null, null, null, output);
InputStream input = new ByteArrayInputStream(output.toByteArray());
Car read = (Car) provider.readFrom(Object.class, Car.class, null, null, null, input);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment