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:

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.