Created
October 26, 2012 21:32
-
-
Save jfirebaugh/3961693 to your computer and use it in GitHub Desktop.
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
<script> | |
var Test = function () {}; | |
Test.prototype.a = function () {}; | |
Test.prototype.b = function () {}; | |
Test.prototype.c = function () {}; | |
Test.prototype.d = function () {}; | |
Test.prototype.e = function () {}; | |
Test.prototype.f = function () {}; | |
Test.prototype.g = function () {}; | |
Test.prototype.h = function () {}; | |
Test.prototype.i = function () {}; | |
Test.prototype.j = function () {}; | |
Test.prototype.k = function () {}; | |
window.ary = []; | |
for (var i = 0; i < 10000; ++i) { | |
ary.push(new Test()); | |
} | |
</script> |
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
<script> | |
var Test = function () { | |
var test = {}; | |
test.a = function () {}; | |
test.b = function () {}; | |
test.c = function () {}; | |
test.d = function () {}; | |
test.e = function () {}; | |
test.f = function () {}; | |
test.g = function () {}; | |
test.h = function () {}; | |
test.i = function () {}; | |
test.j = function () {}; | |
test.k = function () {}; | |
return test; | |
}; | |
window.ary = []; | |
for (var i = 0; i < 10000; ++i) { | |
ary.push(Test()); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
These benchmarks compare the memory usage for classical vs. module pattern objects.
In my tests (Chrome 22.0.1229.94),
classical.html
generates a 1011 KB heap, whilemodule.html
generates a 5.3 MB heap. Most (76%) of the module heap is closures -- one for each function for each instance.Conclusion: beware using the module pattern for heavily allocated classes.