Skip to content

Instantly share code, notes, and snippets.

@nathanaschbacher
Created June 18, 2012 02:26
Show Gist options
  • Save nathanaschbacher/2946474 to your computer and use it in GitHub Desktop.
Save nathanaschbacher/2946474 to your computer and use it in GitHub Desktop.
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
Copy link

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