Comparison between json, thrift and protobuf protocols
Protocol | Encoding time | Decoding time | Payload size (bytes) | Test duration |
---|---|---|---|---|
Json | 216.74875ms | 210.512125ms | 17715 | 2.199822167s |
Protobuf | 198.921792ms | 32.473791ms | 7811 | 1.315487459s |
Thrift | 224.548ms | 46.453167ms | 7853 | 1.438012417s |
- Encoding time +- the same
- Decoding time (on the server): proto 7x faster then json
- Decoding time (on the server): thrift 5x faster then json
- Payload size: 2 times smaller
- Create golang object with faked data
- Marshal it via json, thrift, proto encoder 1000 times
- Unmarshal it 1000 times
- Repeat 2-3 5 times
- Calculate median for each metric via stats
type phoneType int
const (
MOBILE phoneType = iota;
HOME;
WORK;
)
type JsonPhoneNumber struct {
Number string `json:"number"`
PhoneType phoneType `json:"phone_type"`
}
type Timestamp struct {
Seconds int64 `json:"seconds"`
Nanos int32 `json:"nanos"`
}
type JsonPerson struct {
Name string `json:"name"`
Id int32 `json:"id"`
Email string `json:"email"`
Phones []JsonPhoneNumber `json:"phones"`
LastUpdated Timestamp `json:"last_updated"`
}
type JsonAddressBook struct {
People []JsonPerson `json:"people"`
}
Number of person generated per each address book: 100
Operation system | macOS Big Sur |
---|---|
CPU | apple m1 |
Memory | 16 gb |
Cores | 8 |