Skip to content

Instantly share code, notes, and snippets.

@okkez
Last active October 27, 2015 02:00
Show Gist options
  • Save okkez/2b77b32ad3a966446347 to your computer and use it in GitHub Desktop.
Save okkez/2b77b32ad3a966446347 to your computer and use it in GitHub Desktop.
'use strict';
var msgpack5 = require('msgpack5')();
var msgpack = require('msgpack');
var msgpackLite = require('msgpack-lite');
var obj = {
a: 1,
b: 'aaaaaaaaaa',
c: true,
};
var TIMES = 10000;
var packed, unpacked;
console.time('msgpack5');
for (var i = 0; i < TIMES; i++) {
packed = msgpack5.encode(obj);
//unpacked = msgpack5.decode(packed);
}
console.timeEnd('msgpack5');
console.time('msgpack');
for (var i = 0; i < TIMES; i++) {
packed = msgpack.pack(obj);
//unpacked = msgpack.unpack(packed);
}
console.timeEnd('msgpack');
console.time('msgpack-lite');
for (var i = 0; i < TIMES; i++) {
packed = msgpackLite.encode(obj);
}
console.timeEnd('msgpack-lite');
$ node ./benchmark.js
msgpack5: 821ms
msgpack: 36ms
msgpack-lite: 23ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment