Skip to content

Instantly share code, notes, and snippets.

@pgte
Created October 23, 2011 09:00
Show Gist options
  • Save pgte/1307127 to your computer and use it in GitHub Desktop.
Save pgte/1307127 to your computer and use it in GitHub Desktop.
Memory usage of constructor techniques:
Client:
console.log('BEFORE:', process.memoryUsage());
var Rectangle = require('./rectangle');
var rectangles = [];
for(var i = 0; i < 100000; i++) {
rectangles.push(new Rectangle(1,2,3,4));
}
console.log('AFTER:', process.memoryUsage());
1) Using Rectangle.prototype:
AFTER: { rss: 27656192,
vsize: 3115016192,
heapTotal: 24220832,
heapUsed: 13505152 }
2) Using Rectangle closure:
AFTER: { rss: 44900352,
vsize: 3127115776,
heapTotal: 52798592,
heapUsed: 24463608 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment