Msgpack-js vs JSON

JavaScript performance comparison

Revision 21 of this test case created

Info

Comparing the speed of msgpack-js using typed arrays against JSON.parse and JSON.stringify

Preparation code

<script src="https://rawgithub.com/creationix/msgpack-js-browser/master/msgpack.js"></script>
<script>
Benchmark.prototype.setup = function() {
    // took the string data from a protobuf.js test for comparison
    var stringData = {
            "title": "How to Avoid Huge Ships",
            "authors": [
                { "name": "John W. Trimmer" }
            ],
            "isbn": 9780870334337,
            "year_of_publication": 1993,
            "reviews":
            [
                {
                    "reviewer": { "name": "Dan" },
                    "rating": 1,
                    "comments": "Read this book before going......"
                },
                {
                    "reviewer": { "name": "Noel D. Hill" },
                    "rating": 5,
                    "comments": "As the father of two teenagers, I found this book invaluable."
                }
            ]
        };
    var numberData = [
      [1, 2, 3, 4, -1, true, null],
      [3, 6, 5, 4,  1, false, 7],
      [3, 2, 8, 1,  0, true, 0],
      [10, 11, 12, 13,  14, false, true],
      [15, 16, 17, 18, 19, true, null],
      [20, 21, 22, 23,  24, false, 7],
      [25, 26, 27, 28,  29, true, 0],
      100, 200, 300,
      [
        [1, 0, 0, 0, 0],
        [0, 1, 0, 0, 0],
        [0, 0, 1, 0, 0],
        [0, 0, 0, 1, 0],
        [0, 0, 0, 0, 1]
      ]
    ]
   
    var stringifiedJsonStringData = JSON.stringify(stringData);
    var stringifiedJsonNumberData = JSON.stringify(numberData);
    var stringifiedMsgpackStringData = msgpack.encode(stringData);
    var stringifiedMsgpackNumberData = msgpack.encode(numberData);
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
JSON strings Stringify
var result = JSON.stringify(stringData);
pending…
JSON numbers Stringify
var result = JSON.stringify(numberData);
pending…
MsgPack strings Stringify
var result = msgpack.encode(stringData);
pending…
MsgPack numbers Stringify
var result = msgpack.encode(numberData);
pending…
JSON strings Parse
var result = JSON.parse(stringifiedJsonStringData);
pending…
JSON numbers Parse
var result = JSON.parse(stringifiedJsonNumberData);
pending…
MsgPack strings Parse
var result = msgpack.decode(stringifiedMsgpackStringData);
pending…
MsgPack numbers Parse
var result = msgpack.decode(stringifiedMsgpackNumberData);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment