Benchmarking Protocol Buffers, JSON and XML in Go

Shiju Varghese
Jan 30, 2017 · 1 min read

In my post Building High Performance APIs In Go Using gRPC And Protocol Buffers, I have written a simple API in gRPC with Protocol Buffers version 3 as the wire format. In this brief post, I benchmark the performance of Protocol Buffers 3, JSON and XML for both marshaling and unmarshaling.

Herer’s the benchmark tests written in Go:

Here’s the output of benchmark tests:

Image for post
Image for post

The output shows that Protocol Buffers outperforms JSON and XML in both marshaling and unmarshaling. The result shows the following numbers:

  • Protocol Buffers Marshal: 819 ns/op
  • Protocol Buffers Unmarshal: 1163 ns/op
  • JSON Marshal: 3316 ns/op
  • JSON Unmarshal: 7196 ns/op
  • XML Marshal: 9248 ns/op
  • XML Unmarshal: 30485 ns/op

The simple bechmark tests indeed show that Protocol Buffers is a great choice over JSON and XML with REST, when you build massively scalable APIs with gRPC.

You can follow me on twitter at @shijucv. I do provide training and consulting on Go programming language (Golang) and distributed systems architectures, in India.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store