Performance Test – Json Serializers Part III

Note: Don’t for­get to check out Bench­marks page to see the lat­est round up of bina­ry and JSON seri­al­iz­ers.

Fol­low­ing on from my pre­vi­ous test, I have now includ­ed Json­Fx and as well as the Json.Net BSON seri­al­iz­er 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 fol­lows.

image[4]

Graph­i­cal­ly this is how they look:

image

I have includ­ed pro­to­buf-net in this test to pro­vide more mean­ing­ful com­par­i­son for Json.Net BSON seri­al­iz­er since it gen­er­ates a bina­ry pay­load and as such has a dif­fer­ent use case to the oth­er JSON seri­al­iz­ers.

In gen­er­al, I con­sid­er JSON to be appro­pri­ate when the seri­al­ized data needs to be human read­able, a bina­ry pay­load on the oth­er 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­iz­er actu­al­ly 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 bina­ry!

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

Last­ly, whilst the Json.Net BSON seri­al­iz­er offers a slight­ly faster dese­ri­al­iza­tion time com­pared to the Json.Net JSON seri­al­iz­er, it does how­ev­er, have a much slow­er seri­al­iza­tion speed.

Dis­claimers

Bench­marks do not tell the whole sto­ry, and the num­bers will nat­u­ral­ly vary depend­ing on a num­ber of fac­tors such as the type of data being test­ed on. In the real world, you will also need to take into account how you’re like­ly 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 dig­its.