Method #1 - Constructor - 1,515,056k (1.5Gb of Ram)
function blank(){
this.DOM = document.createElement( 'div' );
this.DOM.innerHTML = "Lorem ipsum dolor sit amet... ...posuere cubilia Curae.";
}
var stacked = [];
var amount = 1000000;
for( var i = 0; i < amount; i++ ){
stacked[i] = new blank;
}
Method #2 - Literal - 1,800,000k+ CRASH! (1.8Gb of Ram)
blank = {
gen: function(){
var DOM = document.createElement( 'div' );
DOM.innerHTML = "Lorem ipsum dolor sit amet... ...posuere cubilia Curae.";
return DOM;
}
}
var stacked = [];
var amount = 1000000;
for( var i = 0; i < amount; i++ ){
stacked[i] = blank.gen();
}
NOTE:
The Literal Method did not finish running. It crashed, so the memory is not truly comparable. However, the speed at which the script ran was extremely slow. The Prototype Method pumped up the memory space like a flat tire, The Literal Method crawled so slowly it felt more like trying to pour hot lead into a straw basket.
CONCLUSION:
Careful what you use those literals for!
What's the blank.prototype.DOM; line for? You're not using it's prototype at all, shouldn't this be called Constructor vs new Object?
ReplyDeletecheers
ps: your comment form is broken in FF3, had to fiddle with firebug to post this.
Oops, didn't mean to leave the blank.prototype.DOM in there. You're right, I mean constructor instances.
ReplyDelete