title: Why msgpack is slower than json.parse?
body: <p>I am investigating different data format (string vs masgpack byte) to encode and decode json efficiently. The jsons which I will recieve wont have any schema, atleast to keep it generic, I am assuming the jsons dont follow any specific schema.</p>
  
  <p>Here is a small JS I used to evaluate:</p>
  
  <pre><code>// skip-eslint
  var msgpack = require('msgpack5')() // namespace our extensions
    , encode  = msgpack.encode
    , decode  = msgpack.decode;
  
  var helloWorldObj = { 'hello': 'world' };
  var json = [];
  
  var MAX_DECODE_REPEAT = 10000;
  var MAX_REPEAT  = 100;
  
  console.log('json,data,time');
  //msgpack
  for ( var i=0;i&lt;MAX_REPEAT;i++) {
    json = [];
    // create i+1 length json array
    for(var k=0;k&lt;=i;k++){
      json.push(helloWorldObj);
    }
  
    // encode the json array
    var encodedJson = encode(json);
    var start = new Date().getTime();
    // start decoding =&gt;msgpack
    for(var count=0;count&lt;MAX_DECODE_REPEAT;count++){
      decode(encodedJson);
    }
    var end = new Date().getTime();
    var time = end-start;
    console.log(json.length +',' + encodedJson.length + ','+time);
  
  }
  
  // JSON.parse
  for ( var i=0;i&lt;MAX_REPEAT;i++) {
    json = [];
    // create i+1 length json array
    for(var k=0;k&lt;=i;k++){
      json.push(helloWorldObj);
    }
  
    // stringify the json array
    var jsonString = JSON.stringify(json);
    var start = new Date().getTime();
    // start decoding =&gt;msgpack
    for(var count=0;count&lt;MAX_DECODE_REPEAT;count++){
      JSON.parse(jsonString);
    }
    end = new Date().getTime();
    time = end-start;
    console.log(json.length +',' + jsonString.length*2 + ','+time);
  }
  </code></pre>
  
  <p>The logic is simple: I am increasing the length of the array and trying to find out the time taken by the decoder to decode the array 10000 times.</p>
  
  <p>To my surprise, msgpack is taking 10 times more than json.parse. To decode 100 length array msgpack takes 4694 ms whereas json.parse takes only 378 ms, even though msgpack compresses the array to 1303 bytes from 3602 bytes (assuming each character takes 2 bytes).</p>
  
  <p>What I initially assumed is a smaller size to decode would mean smaller time to decode but its definitely not the case. Any idea why? Do you see any issue with the program to evaluate msgpack?</p>
  
  <p>Thanks</p>