Created
November 2, 2011 03:29
-
-
Save normanzb/1332776 to your computer and use it in GitHub Desktop.
Memory Usage Comparison -- OO (Knockout Style)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ObjectContainer = []; | |
var HOW_MANY_OBJ = 100000; | |
var memoryHolder; | |
function Heavy (){ | |
var ret=function(){}; | |
ret.load = function(){ | |
var str = | |
'gabagesgabagesgabagesgabagesgabages'; | |
for(var i = 0; i < 9999; i++){ | |
str+=str; | |
} | |
this._loads = str; | |
}; | |
ret.release = function(){ | |
this._loads = null; | |
} | |
return ret; | |
} | |
function Light(){ | |
} | |
var p = Light.prototype; | |
p.load = function(){ | |
var str = | |
'gabagesgabagesgabagesgabagesgabages'; | |
for(var i = 0; i < 9999; i++){ | |
str+=str; | |
} | |
this._loads = str; | |
}; | |
p.release = function(){ | |
this._loads = null; | |
} | |
console.log('Creating Heavy objects...'); | |
memoryHolder = console.memory.usedJSHeapSize; | |
console.log(console.memory); | |
console.time('Heavy'); | |
for(var i = 0; i < HOW_MANY_OBJ; i++){ | |
ObjectContainer.push(Heavy()); | |
} | |
console.timeEnd('Heavy'); | |
console.log(console.memory); | |
console.log("Used JS Heap: " + (console.memory.usedJSHeapSize - memoryHolder)); | |
console.log('Creating Light objects...'); | |
memoryHolder = console.memory.usedJSHeapSize; | |
console.log(console.memory); | |
console.time('Light'); | |
for(var i = 0; i < HOW_MANY_OBJ; i++){ | |
ObjectContainer.push(new Light); | |
} | |
console.timeEnd('Light'); | |
console.log(console.memory); | |
console.log("Used JS Heap: " + (console.memory.usedJSHeapSize - memoryHolder)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment