On Tue, 2009-08-18 at 07:43 -0700, Tai wrote:
> What I am measuring in writeObject() and readObject() is:
> 
> 1) For PB I only measure the writeDelimitedTo() and parseDelimitedFrom
> public class PojoUsingPB extends AbstractPojo implements Serializable
> {
> ...
>     private void writeObject(java.io.ObjectOutputStream out) throws
> IOException {
> ...
>         long start = System.nanoTime();
>         message.writeDelimitedTo(out);
>         long end = System.nanoTime();
> ...
>     }
> 
>     private void readObject(java.io.ObjectInputStream in)
>             throws ClassNotFoundException, IOException {
>         long start = System.nanoTime();
>         PojoMessage.Pojo message = PojoMessage.Pojo.parseDelimitedFrom
> (in);
>         long end = System.nanoTime();
> ...
> 
> 2) In Java I measure the ObjectOutputStream.writeObject() and
> ObjectInputStream.readObject():
> public class PojoUsingJava extends AbstractPojo implements
> Serializable {
> ...
>     private void writeObject(java.io.ObjectOutputStream out) throws
> IOException {
>         long start = System.nanoTime();
>         out.writeObject(key);
>         out.writeObject(value);
>         out.writeBoolean(someBoolean);
>         long end = System.nanoTime();
> ...
>     }
> 
>     private void readObject(java.io.ObjectInputStream in)
>             throws ClassNotFoundException, IOException {
>         long start = System.nanoTime();
>         key = (String) in.readObject();
>         value = (String) in.readObject();
>         someBoolean = in.readBoolean();
>         long end = System.nanoTime();
> ...
> 
> I don't know where I could have done something wrong. The results I am
> getting is:
> Duration using Java > Protocol Buffers
> Average remote time = 111309 > 122173 nanosecs
> Average serialization time = 3609 > 6586 nanosecs
> Average de-serialization time = 3533 > 9287 nanosecs
> 
> Based on that PB seems to be slower and I am not coming to the same
> conclusion as stated in other performance tests?!

That's because you create a PB, builder and call build for each written
object. 
The Java serialization doesn't have to do that, it just feeds the fields
of your POJO directly to the stream.

And the same applies to the deserialization.

If you were writing much more than 2 fields, then you'd see the weight
of creating the objects be less compared to the serialization time.

I'm not familiar with Java Serialization (anymore), but I think I
remember overriding writeObject and readObject still uses java
serialization for some parts of the current object (including
superclass, and so on). 
Shouldn't you use instead an Externalizable object?

My suggestion:
 * benchmark in situation or with larger close to production objects
 * if your objects are immutable, create the builder in your
constructer, and build at that time. This way you can write multiple
time without incurring the creation cost.
 * use an Externalizable object

HTH,
-- 
Brice Figureau
My Blog: http://www.masterzen.fr/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to