The basic performance of Protocol Buffers in a simple, unscientific experiment…
Encode One PositionData to byte 595 nanoseconds Decode One PositionData from byte 970 nanoseconds
The basic performance of jsonlib in a simple, unscientific experiment…
Encode One PositionData to String 30 microseconds Decode One PositionData from String 41 microseconds
Granted this isn’t an apples-to-apples comparison. The Protocol Buffers example is just encoding a PositionData object to a byte and storing it in memory, where the JSON example is encoding a PositionData object to a String and storing it in memory. The ProtocolBuffers example does three million encode/decode operations and then takes an average to calculate the time for each operation and the JSON example performs half a million operations. JSON is also doing some introspection to figure out the properties on the PositionData object where Protocol Buffers already knows the type it is trying to encode.
Still, the difference is dramatic. Protocol Buffers is the clear winner in terms of encoding and decoding performance. Winner: Protocol Buffers ~50x faster than JSON-lib at encoding and ~42x faster than JSON at encoding.
Next up, JSON vs. XML.
For more details, see “14.7. Measuring Protocol Buffers Performance” and “13.9. Measuring JSON Encoding and Parsing Performance”.