JSON vs Protobuf.js (v4)

Revision 4 of this benchmark created on


Preparation HTML

<script src="http://rawgit.com/dcodeIO/ByteBuffer.js/master/dist/ByteBufferAB.min.js"></script>
<script src="http://rawgit.com/dcodeIO/ProtoBuf.js/master/dist/ProtoBuf.min.js"></script>

Setup

var testStr = (new Array(5000)).join('{"question":"What is the answer to life and everything?", "answer": 23},');
    var testData = JSON.parse("[" + testStr.substr(0, testStr.length - 1) + "]");
    
    var builder = dcodeIO.ProtoBuf.newBuilder();
    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.