The reason I had to redo the benchmark and not just look it up online is because I couldn't find a benchmark that includes all the serializers I wanted to test - This is exactly why I'm posting this online, maybe this will save someone else's time.
As far as for trade offs we thought of when choosing the best serializer(s) for our development teams we considered the following:
- (De)Serialization performance
- Payload size
- Cross-platform ability
- Readability of the serialized result (ease things up on debugging and logging reads).
So, for us to get a wide view on things I tested both string based and binary serializers.
In the string section:
In the binary section:
- Protobuf-net
- DataContractSerializer (set up to binary)
- XMLSerializer (set up to binary)
- BinaryFormatter (just for reference, as it isn't cross platform and known for it's poor performance due to it's extensive usage of reflection).
In order to choose the right metrics I looked up in Sasha Goldshtein's awsome book who did a very similar benchmark.
The Test
In order to do the benchmark I used AdventureWork's top 100K Sales.SalesOrderDetail rows.
I loaded these rows into this POCO:
The reason for the BaseMessageClass and the inheritance is our common use case where we have one endpoint in the code that deserializes the bytes into a base class and then dispatches it according to it's actual type.
For every serializer I simply measured using Stopwatch the time to serially serialize 100K objects into a memory stream and then measured the time to serially deserialize the output of the previous stage into the base message.
Between each test I ran GC.Collect() in order to avoid GC during the measurements.
I did also try to measure every single serialization and deserialization operation but as the results on the fast serializers were mostly under a millisecond I got no relevant results there.
The Results
And the Winners
When it comes to performance and payload size Protobuf-net is without a doubt the best serializer by a magnitude.
If you insist of having a readable payload (or insist of Json as it is pretty much a standard these days when it comes to web apis) and wish to compromise as least as you can on performance I guess ServiceStack's JsonSerializer is a good choice for you with a descent performance and reasonable payload size.
No comments:
Post a Comment