Created
June 24, 2011 04:54
-
-
Save billywhizz/1044253 to your computer and use it in GitHub Desktop.
comparing buffalo BSON v JSON
This file contains hidden or 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 buffalo = require("../buffalo"); | |
| function test(obj, iter, fn, name) { | |
| var then = new Date().getTime(); | |
| var p; | |
| var runs = 0; | |
| while(iter--) { | |
| p = fn(obj); | |
| runs++ | |
| } | |
| var now = new Date().getTime(); | |
| var elapsed = (now-then)/1000; | |
| console.log(name + "\t" + elapsed.toFixed(2) + "\t" + runs + "\t" + (runs/elapsed).toFixed(2)); | |
| } | |
| var msg = { | |
| int: 255, | |
| int16: 65535, | |
| int32: 65536, | |
| float: 200.23, | |
| account: "test123", | |
| bool: true, | |
| none: null, | |
| array: [1,2,3] | |
| }; | |
| console.log("BSON: " + JSON.stringify(buffalo.parse(buffalo.serialize(msg)))); | |
| console.log("BSON.size: " + buffalo.serialize(msg).length); | |
| console.log("JSON: " + JSON.stringify(JSON.parse(JSON.stringify(msg)))); | |
| console.log("JSON.size: " + JSON.stringify(msg).length); | |
| var runs = parseInt(process.ARGV[2]); | |
| test(msg, runs, JSON.stringify, "JSON.stringify"); | |
| test(msg, runs, buffalo.serialize, "BSON.serialize"); | |
| test(JSON.stringify(msg), runs, JSON.parse, "JSON.parse"); | |
| test(buffalo.serialize(msg), runs, buffalo.parse, "BSON.parse"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment