Created
November 4, 2013 14:19
-
-
Save alepez/7303125 to your computer and use it in GitHub Desktop.
node.js profiling memory classical vs prototypal
This file contains hidden or 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 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