JSON vs Protobuf

I did a few tests to compare the data payload sizes of different serialization methods on .NET client server communications.

The test was basically to execute a request/response 20 times.

Request

[Serializable]
[ProtoContract]
public class GetRatingRequest
{
        [ProtoMember(1)]
        public int Rating;
        [ProtoMember(2)]
        public int Count;
        [ProtoMember(3)]
        public float A;
        [ProtoMember(4)]
        public float B;
        [ProtoMember(5)]
        public float C;
        [ProtoMember(6)]
        public float D;
        [ProtoMember(7)]
        public float E;
}

Response

[Serializable]
[ProtoContract]
public class GetRatingResponse
{
        [ProtoMember(1)]
        public List<Rating> Ratings;
}

[Serializable]
[ProtoContract]
public class Rating
{
        [ProtoMember(1)]
        public bool HighRating { get; set; }
        [ProtoMember(2)]
        public RatingDetail Details { get; set; }
        [ProtoMember(3)]
        public RatingMetadata[] Metadata{ get; set; }
}

Results

Plain JSONGZIP JSONProtobufGZIP Protobuf
Request KB13.2413.337.857.93
Response KB112081.5234.2517.76

Surprisingly, using GZIP on top of Protobuf reduced the size of the request even further.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.