JSON vs Protobuf.js (v2)

Revision 2 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 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
            },
            {
                "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
JSON.stringify(testData);
ready
Protobuf overhead
JSON.stringify(new MsgBuilder(testData))
ready

Revisions

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