Last active
August 29, 2015 14:24
-
-
Save nickbalestra/6b9a19f5532aedbbf80e to your computer and use it in GitHub Desktop.
Istantiation Patterns - Performance Test
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 Functional = function(){ | |
var istance = {}; | |
var private = {}; | |
istance.firstMethod = function(){}; | |
istance.secondMethod = function(){}; | |
istance.thirdMethods = function(){}; | |
istance.fourthMethod = function(){}; | |
istance.fifthMethod = function(){}; | |
istance.lastMethod = function(){}; | |
return istance; | |
}; |
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
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Istantation Patterns Permormance Test</title> | |
<script src="functional.js"></script> | |
<script src="functionalShared.js"></script> | |
<script src="protototypal.js"></script> | |
<script src="pseudoclassical.js"></script> | |
</head> | |
<body> | |
<script> | |
function test(num, instantiationPattern, name){ | |
var mock; | |
var start = window.performance.now(); | |
for (var i = 0; i < num; i++) { | |
if (name === "pseudoclassical"){ | |
mock = new instantiationPattern(); | |
} else { | |
mock = instantiationPattern(); | |
} | |
} | |
var end = window.performance.now(); | |
var elapsed = end - start; | |
console.log("Created " + num + " " + name + " istances in " + elapsed + " milliseconds"); | |
} | |
test(1000000, Functional, "functional"); | |
test(1000000, FunctionalShared, "functionalShared"); | |
test(1000000, Prototypal, "prototypal"); | |
test(1000000, Pseudoclassical, "pseudoclassical"); | |
</script> | |
</body> | |
</html> |
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 Prototypal = function(){ | |
var istance = Object.create(protototypalMethods); | |
istance._private = {}; | |
return istance; | |
} | |
var protototypalMethods = { | |
firstMethod: function(){}, | |
secondMethod: function(){}, | |
thirdMethods: function(){}, | |
fourthMethod: function(){}, | |
fifthMethod: function(){}, | |
lastMethod: function(){} | |
}; |
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 Pseudoclassical = function(){ | |
this._private = {}; | |
this.firstMethod = function(){}; | |
this.secondMethod = function(){}; | |
this.thirdMethods = function(){}; | |
this.fourthMethod = function(){}; | |
this.fifthMethod = function(){}; | |
this.lastMethod = function(){}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment