Benchmarking Protocol Buffers, JSON and XML in Go

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.

Consulting Solutions Architect and Trainer on Go and Distributed Systems, with focus on Microservices and Event-Driven Architectures. Author of two books on Go.

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