JSON vs Protobuf.js (v13)

Revision 13 of this benchmark created on


Preparation HTML

<script src="http://rawgit.com/dcodeIO/ByteBuffer.js/master/dist/bytebuffer.min.js"></script>
<script src="//cdn.rawgit.com/dcodeIO/protobuf.js/5.0.1/dist/protobuf.js"></script>

Setup

var testData = {
      question: 'What is the answer to life and everything?',
      answer: 23
    };
    
    var builder = new dcodeIO.ProtoBuf.Builder();
    builder.create({
      "name": "Msg",
      "fields": [{
        "rule": "required",
        "options": {},
        "type": "string",
        "name": "question",
        "id": 1
      }, {
        "rule": "required",
        "options": {},
        "type": "int32",
        "name": "answer",
        "id": 2
      }, ]
    });
    
    var MsgBuilder = builder.build('Msg'),
      protoMsg = new MsgBuilder(testData).encode().toArrayBuffer(),
      jsonMsg = JSON.stringify(testData);

Test runner

Ready to run.

Testing in
TestOps/sec
JSON encode
JSON.stringify(testData);
ready
Protobuf encode
new MsgBuilder(testData).encode().toArrayBuffer()
ready
JSON decode
JSON.parse(jsonMsg);
ready
Protobuf decode
MsgBuilder.decode(protoMsg);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.