JSON vs Protobuf.js (v6)

Revision 6 of this benchmark created by aaa 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 testData = {
        question: 'What is the answer to life and everything?',
        answer: 23
    };
    
    var builder = dcodeIO.ProtoBuf.newBuilder();
    builder.create({
        "name": "Msg",
        "fields": [
            {
                "rule": "required",
                "options": {},
                "type": "string",
                "name": "question",
                "id": 1
            }
         ]
    });
    
    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.