Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.