Skip to content

@DracoBlue /gist:354628
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
extend = process.mixin;
extend(true, {}, {})
var sys = require("sys");
var test_object = {};
var benchmark = function(function_name, function_object) {
var before_timestamp = new Date().getTime();
function_object();
var after_timestamp = new Date().getTime();
sys.puts(" " + Math.floor((after_timestamp - before_timestamp)) + 'ms ' + function_name);
}
var a_key = "", b_key = "", c_key = "", d_key = "";
for (var i=0; i < 1; i++) {
a_key = "a" + Math.floor(i / 100000);
b_key = "b" + Math.floor(i / 10000);
c_key = "c" + Math.floor(i / 1000);
d_key = "d" + Math.floor(i / 100);
test_object[a_key] = test_object[a_key] || {};
test_object[a_key][b_key] = test_object[a_key][b_key] || {};
test_object[a_key][b_key][c_key] = test_object[a_key][b_key][c_key] || {};
test_object[a_key][b_key][c_key][d_key] = test_object[a_key][b_key][c_key][d_key] || {};
test_object[a_key][b_key][c_key][d_key]["e" + i] = i + "v";
}
sys.puts("JSON-String: " + JSON.stringify(test_object).length + " characters");
benchmark("3000x JSON.parse(JSON.stringify(object))", function() {
for (var k=0; k<3000;k++) {
JSON.parse(JSON.stringify(test_object));
}
});
benchmark("3000x extend(true, {}, object)", function() {
for (var k=0; k<3000;k++) {
extend(true, {}, test_object);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.