Skip to content

Instantly share code, notes, and snippets.

@bjouhier
Created November 6, 2011 13:27
Show Gist options
  • Save bjouhier/1342872 to your computer and use it in GitHub Desktop.
Save bjouhier/1342872 to your computer and use it in GitHub Desktop.
jsurl bench
"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