Created
November 6, 2011 13:27
-
-
Save bjouhier/1342872 to your computer and use it in GitHub Desktop.
jsurl bench
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
"use strict"; | |
var JSURL = require("jsurl"); | |
function bench(name, count, fn) { | |
var t0 = Date.now(); | |
for (var i = 0; i < count; i++) | |
fn(); | |
console.log(name + ": " + (Date.now() - t0)); | |
} | |
var obj = {name:"John Doe",age:42,children:["Mary","Bill"]}; | |
var jsurlOut = JSURL.stringify(obj); | |
var jsonOut = JSON.stringify(obj); | |
var jsonUrlOut = encodeURIComponent(jsonOut); | |
var count = 100000; | |
bench("JSURL.stringify", count, function() { | |
JSURL.stringify(obj); | |
}); | |
bench("JSON.stringify", count, function() { | |
JSON.stringify(obj); | |
}); | |
bench("JSON.stringify + URL encode", count, function() { | |
encodeURIComponent(JSON.stringify(obj)); | |
}); | |
bench("JSURL.parse", count, function() { | |
JSURL.parse(jsurlOut); | |
}); | |
bench("JSON.parse", count, function() { | |
JSON.parse(jsonOut); | |
}); | |
bench("URL decode + JSON.parse", count, function() { | |
JSON.parse(decodeURIComponent(jsonUrlOut)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment