Skip to content

Instantly share code, notes, and snippets.

@alepez
Created November 4, 2013 14:19
Show Gist options
  • Save alepez/7303125 to your computer and use it in GitHub Desktop.
Save alepez/7303125 to your computer and use it in GitHub Desktop.
node.js profiling memory classical vs prototypal
var memwatch = require('memwatch');
var classical = function() {
var Apple = function(options) {
var self = this;
var color = options.color;
var getColor = function() {
return color;
};
self.getColor = getColor;
}
var hd = new memwatch.HeapDiff();
var arr = [];
for (var i = 0; i < 99999; i += 1) {
arr.push(new Apple(i));
}
return hd.end();
};
var prototypal = function() {
var apple = function(options) {
var that = {};
var color = options.color;
var getColor = function() {
return color;
};
that.getColor = getColor;
return that;
};
var hd = new memwatch.HeapDiff();
var arr = [];
for (var i = 0; i < 99999; i += 1) {
arr.push(apple(i));
}
return hd.end();
};
if (process.argv[2] === "classical" ) {
console.log("== Classical == \n");
console.log(classical().change);
}
if (process.argv[2] === "prototypal" ) {
console.log("== Prototypal == \n");
console.log(prototypal().change);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment