Note: Don’t for­get to check out Bench­marks page to see the lat­est round up of binary and JSON serializers.

Fol­low­ing on from my pre­vi­ous test, I have now included JsonFx and as well as the Json.Net BSON seri­al­izer in the mix to see how they match up.

The results (in mil­lisec­onds) as well as the aver­age pay­load size (for each of the 100K objects seri­al­ized) are as follows.

image[4]

Graph­i­cally this is how they look:

image

I have included protobuf-net in this test to pro­vide more mean­ing­ful com­par­i­son for Json.Net BSON seri­al­izer since it gen­er­ates a binary pay­load and as such has a dif­fer­ent use case to the other JSON serializers.

In gen­eral, I con­sider JSON to be appro­pri­ate when the seri­al­ized data needs to be human read­able, a binary pay­load on the other hand, is more appro­pri­ate for com­mu­ni­ca­tion between applications/services.

Obser­va­tions

You can see from the results above that the Json.Net BSON seri­al­izer actu­ally gen­er­ates a big­ger pay­load than its JSON coun­ter­part. This is because the sim­ple POCO being seri­al­ized con­tains an array of 10 inte­gers in the range of 1 to 100. When the inte­ger ‘1’ is seri­al­ized as JSON, it’ll take 1 byte to rep­re­sent as one char­ac­ter, but an inte­ger will always take 4 bytes to rep­re­sent as binary!

In com­par­i­son, the pro­to­col buffer for­mat uses varint encod­ing so that smaller num­bers take a smaller num­ber of bytes to rep­re­sent, and it is not self-describing (the prop­erty names are not part of the pay­load) so it’s able to gen­er­ate a much much smaller pay­load com­pared to JSON and BSON.

Lastly, whilst the Json.Net BSON seri­al­izer offers a slightly faster dese­ri­al­iza­tion time com­pared to the Json.Net JSON seri­al­izer, it does how­ever, have a much slower seri­al­iza­tion speed.

Dis­claimers

Bench­marks do not tell the whole story, and the num­bers will nat­u­rally vary depend­ing on a num­ber of fac­tors such as the type of data being tested on. In the real world, you will also need to take into account how you’re likely to inter­act with the data, e.g. if you know you’ll be dese­ri­al­iz­ing data a lot more often than seri­al­iz­ing them then dese­ri­al­iza­tion speed will of course become less impor­tant than seri­al­iza­tion speed!

In the case of BSON and inte­gers, whilst it’s less effi­cient (than JSON) when seri­al­iz­ing small num­bers, it’s more effi­cient when the num­bers are big­ger than 4 digits.

Share

9 Responses to “Performance Test – Json Serializers Part III

  1. Marc Gravell says:

    I have included protobuf-net in this test to…” — did I miss it? You have got me won­der­ing whether I should try my hand at BSON, though :)

  2. Marc Gravell says:

    Ah, my bad — I was look­ing at the graph, not the table. Feel free to delete the above.

  3. theburningmonk says:

    Hey Marc, not to worry, I just included the serialization/deserialization times for protobuf-net purely as a ref­er­ence to see how well BSON matches up to it.

    I would prob­a­bly put it in the binary seri­al­iz­ers test instead as it’s not really fair to put them up against JSON seri­al­iz­ers as the use cases for a wire for­mat and a text for­mat are very different.

  4. John Cole says:

    Any chance of adding the Mon­goDB c# dri­ver Bson Serializer/Deserializer? Kind of an obvi­ous one to use if you’re using Mongo, but I’d be inter­ested to see how it stacks up against the competition.

  5. Justin says:

    Love the bench­marks and the test har­ness you made. Thanks so much for putting in the work. I have few sug­ges­tions: some of the time spent seri­al­iz­ing is actu­ally spent by the garbage col­lec­tor run­ning so I think before test­ing each of the seri­al­iz­ers you should be doing a full col­lec­tion. This would keep seri­al­izer n from pay­ing for the sins (exces­sive allo­ca­tions) of seri­al­izer n-1. If you wanted to get really fancy there is a native api that would allow you to track just the time spent by the thread doing the serialization.

    Another sug­ges­tion would be to sep­a­rate initialization/setup time from seri­al­iza­tion time. Most of the seri­al­iz­ers you are test­ing build a cache of infor­ma­tion about the types they are seri­al­iz­ing so the first seri­al­iza­tion of a type nec­es­sar­ily takes much longer than sub­se­quent seri­al­iza­tions. It would be cool to see this quan­ti­fied for each of the seri­al­iz­ers. I.E. maybe I should use seri­al­izer X for my high through­put web ser­vices because though it warms up slowly it seri­al­izes much faster than the others.

    Just my two cents. Again thanks so much for the effort.

  6. theburningmonk says:

    @John Cole — sure, I’ll include it in the bench­marks, sounds like a good addi­tion to the tests

  7. theburningmonk says:

    @Justin — Thanks for the suggestions!

    track only time spent on seri­al­iza­tion” — the amount of stress a seri­al­izer exerts on the GC and the con­se­quent time spent in GC is also an impor­tant per­for­mance char­ac­ter­is­tic that should be taken into account. But it might add a lot of value to see both times (GC time + seri­al­iza­tion time), I’ll look into col­lect­ing GC data for each test, they might reveal inter­est­ing stories.

    full GC before each test” — good idea, though I think it might make more sense to do the full GC at the end of each test and include the GC time for that test for the same rea­son as above.

    sep­a­rate initialization/setup time” — over a large num­ber of seri­al­iza­tions in each trial, over 5 tri­als, the impact of the ini­tial­iza­tion time should become neg­li­gi­ble, so I don’t think it’ll pro­duce any notice­able dif­fer­ence in the results.
    Also, the tests are fil­ter­ing out the min and max trial times, so if the first trial takes sig­nif­i­cantly longer because of the ini­tial­iza­tion, the times from that trial would not be taken into account when work­ing out the final average.

    once again, thanks for the sug­ges­tions, they’re much appreciated :-)

  8. […] to the last set of results, you can see that the lat­est ver­sion of JsonFX seems have gone much much slower on […]

Leave a Reply