public
Last active

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
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);
}
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.