Hi Guys,
I wrote a JMH benhmark to compare the serialization performance of Avro
(1.8.2) & Protobuf (3.5.0) in java 1.8.
According to JMH, Protobuf can serialize 4.7 million ops/sec where as Avro
can only do 800k per second.
The test data that was serialized is around 200 bytes and I generated
schema for both Avro and Protobuf.
Here is my Avro serialization code, can someone familiar with Avro ensure
that I haven't made some cardinal mistake?
The code highlighted in bold is what JMH benchmarked.
Many Thanks,
Vic
public final class AvroSerialization{
private BinartEncoder encoder;
private final SpecificDatumWriter writer;
public AvroSerialization( ){
this.writer = new SpecificDatumWriter( AvroGeneratedClass.class );
}
//MyDataObject = A pojo that contains the data to be serialized
*public final byte[] serialize( MyDataObject data ){
ByteArrayOutputStream out = new ByteArrayOutputStream( 1024 );
encoder = EncoderFactory.get().binaryEncoder( out, encoder );
AvroGeneratedClass avroData = createAvro( data ); writer.write(
avroData, encoder ); encoder.flush(); byte[] bytes =
out.toByteArray(); return bytes;}*
//AvroGeneratedClass = Class generated by the Avro Schema
public final static AvroGeneratedClass createAvro( MyDataObject data ){
AvroGeneratedClass avroData = AvroGeneratedClass.newBuilder()
.setXXX( data.getXXX )
.setXXX( data.getXXX )
...
return avroData;
}
}
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.