1

I'm interested in a certain situation. I have an object in C# that I would like to serialize and deserialize.

I'm kind of conducting an experiment. I'm trying to see if switching the libraries of protobuf will have any affect on the time it takes to serialize and deserialize an object. Additionally, I'm throwing an XML serialization in the mix to see if that can compete as well, even though I'm pretty sure protobuf is faster.

In terms of speed, is there a clear, definite winner between protobuf and XML? Assuming everything was done consistently? i.e. Same path, parallel code, straightforward, etc.. And also, would the speed be affected if I switched the libraries that the protobuf is using to serialize and deserialize? (From protobuf-net to protobuf C# port?) I'm quite new to this so I do not know the answer yet, but what I heard was that protobuf is supposed to be smaller, faster, and easier than XML.

Any insight is greatly appreciated! Thanks! Off to write the tests now.

tf.rz
  • 1,347
  • 6
  • 18
  • 47

1 Answers1

1

Will protobuf be quicker? Absolutely. I've profiled this many many times, all with similar results, for examples:

and many passing comments from happy users. I honenstly haven't compared to Jon's version in a long while, and I haven't done a direct v2 comparison, but here's a key point: in most cases the final bandwidth is the limiting factor in network performance, and they are the same wire format so should be pretty much identical there. Of course, protobuf is also demonstrably cheaper to read and write too, but unless you are on a mobile device that is secondary.

The big difference between protobuf-net and the port is that the ported version (Jon's) adopts (quite reasonably) the protobuf approach (immutable/generated objects etc) which might it hard to retrofit to an existing type model - you would have to introduce a separate DTO layer and map to it. Which isn't a big problem - simply a consideration. And for that reason you might find it hard to do a direct comparison between XmlSerializer and the port; they both get your data, but the routes are very different. Conversely, protobuf-net deliberately positions itself as a very similar API to XmlSerializer etc, so it is pretty easy to do a test suite using the same objects etc - just changing the serializer.

Community
  • 1
  • 1
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • thank you very much for the information you have provided. A well-deserving answer. I also comment with interesting news. In the tests that I ran, Jon's version and yours were similar and by far much, much, MUCH faster than xml. I ran a loop of 10000 iterations and the difference was about 1.239 seconds between protobuf and XML, with protobuf taking the cake easily. Regardless of which library I used, be it Protobuf-net or the ported version, XML serialization had no chance. Thanks again Marc! – tf.rz Jul 06 '11 at 17:37