Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Comparing encode/decode performance of MsgPack Node.js implementations against JSON.
var msgpack = require('msgpack-js');
var msgpack2 = require('msgpack2');
var os = require('os');
console.log(" OS: " + os.type() + " " + os.release() + " (" + os.arch() + ")");
console.log("RAM: " + os.totalmem()/1048576 + " MB (total), " + os.freemem()/1048576 + " MB (free)");
console.log("CPU: " + os.cpus()[0].speed + " MHz " + os.cpus()[0].model);
for(var r = 1; r < 4; r++) {
console.log("\nRun #" + r + ":");
var obj = {'abcdef' : 1, 'qqq' : 13, '19' : [1, 2, 3, 4]};
var start = Date.now();
for(var i = 0; i < 500000; i++) {
JSON.parse(JSON.stringify(obj));
}
var stop = Date.now();
console.log("\t JSON: " + (stop - start) + "ms");
start = Date.now();
for(var i = 0; i < 500000; i++) {
msgpack.decode(msgpack.encode(obj));
}
stop = Date.now();
console.log("\tMsgPack JS: " + (stop - start) + "ms");
start = Date.now();
for(var i = 0; i < 500000; i++) {
msgpack2.unpack(msgpack2.pack(obj));
}
stop = Date.now();
console.log("\tMsgPack 2: " + (stop - start) + "ms");
}
OS: Darwin 11.4.0 (x64)
RAM: 4096 MB (total), 2137.125 MB (free)
CPU: 1800 MHz MacBookAir4,2
Run #1:
JSON: 1556ms
MsgPack JS: 5860ms
MsgPack 2: 6907ms
Run #2:
JSON: 1519ms
MsgPack JS: 5813ms
MsgPack 2: 6879ms
Run #3:
JSON: 1432ms
MsgPack JS: 5839ms
MsgPack 2: 6958ms
@wbrown

This comment has been minimized.

Copy link

@wbrown wbrown commented Mar 13, 2014

Comparing Node.JS's JSON vs json_sans_eval.js, minified and unminified.

 OS: Linux 3.12.8-1-ARCH (x64)
RAM: 15740.04296875 MB (total), 2234.4609375 MB (free)
CPU: 2900 MHz Intel(R) Core(TM) i3-4130T CPU @ 2.90GHz

Run #1:
          JSON: 1022ms
     jsonParse: 2397ms
    jsonParseM: 2157ms
    MsgPack JS: 7411ms

Run #2:
          JSON: 930ms
     jsonParse: 2233ms
    jsonParseM: 2124ms
    MsgPack JS: 7379ms

Run #3:
          JSON: 942ms
     jsonParse: 2197ms
    jsonParseM: 2115ms
    MsgPack JS: 7330ms
@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Apr 21, 2016

var msgpack5 = require('msgpack5')();
var os = require('os');

console.log(" OS: " + os.type() + " " + os.release() + " (" + os.arch() + ")");
console.log("RAM: " + os.totalmem()/1048576 + " MB (total), " + os.freemem()/1048576 + " MB (free)");
console.log("CPU: " + os.cpus()[0].speed + " MHz " + os.cpus()[0].model);

for(var r = 1; r < 4; r++) {
  console.log("\nRun #" + r + ":");
  var obj = {'abcdef' : 1, 'qqq' : 13, '19' : [1, 2, 3, 4]};

  var start = Date.now();
  for(var i = 0; i < 500000; i++) {
    JSON.parse(JSON.stringify(obj));
  }
  var stop = Date.now();
  console.log("\t      JSON: " + (stop - start) + "ms");

/*
  start = Date.now();
  for(var i = 0; i < 500000; i++) {
    msgpack.decode(msgpack.encode(obj));
  }
  stop = Date.now();
  console.log("\tMsgPack JS: " + (stop - start) + "ms");
  */


  start = Date.now();
  for(var i = 0; i < 500000; i++) {
    msgpack5.decode(msgpack5.encode(obj));
  }
  stop = Date.now();
  console.log("\tMsgPack  5: " + (stop - start) + "ms");
}
C:\WT-NMP\JXcore>node benchmark
 OS: Windows_NT 6.1.7601 (x64)
RAM: 8174.1171875 MB (total), 5280.40234375 MB (free
CPU: 3515 MHz AMD FX(tm)-6300 Six-Core Processor

Run #1:
              JSON: 1976ms
        MsgPack  2: 24147ms

Run #2:
              JSON: 1967ms
        MsgPack  2: 24284ms

Run #3:
              JSON: 1876ms
        MsgPack  5: 24616ms

25 seconds? What the fuck!?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment