Created
June 18, 2012 02:26
-
-
Save nathanaschbacher/2946474 to your computer and use it in GitHub Desktop.
Comparing encode/decode performance of MsgPack Node.js implementations against JSON.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
25 seconds? What the fuck!?