Created
April 8, 2012 23:33
-
-
Save jstsch/2340375 to your computer and use it in GitHub Desktop.
JS OOP comparision
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<title>untitled</title> | |
<script type="text/javascript" charset="utf-8"> | |
/* <![CDATA[ */ | |
var startTime = new Date().getTime(); | |
Cat = { | |
createNew: function(){ | |
var cat = { }; | |
cat.makeSound = function(){ //add logic | |
var j = 0; | |
for (var i = 0; i < 100; i++) { | |
j += Math.round(Math.random() * 100); | |
} | |
return j; | |
} | |
return cat; | |
} | |
} | |
var j = 0; | |
for (var i = 0; i < 10000; i++) { | |
var myCat = Cat.createNew(); | |
j += myCat.makeSound(); | |
} | |
var endTime = new Date().getTime(); | |
console.log(j); | |
console.log(endTime - startTime); | |
/* ]]> */ | |
</script> | |
</head> | |
<body> | |
</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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<title>untitled</title> | |
<script type="text/javascript" charset="utf-8"> | |
/* <![CDATA[ */ | |
var startTime = new Date().getTime(); | |
function Cat() { | |
} | |
Cat.prototype.makeSound = function() { | |
var j = 0; | |
for (var i = 0; i < 100; i++) { | |
j += Math.round(Math.random() * 100); | |
} | |
return j; | |
}; | |
var j = 0; | |
for (var i = 0; i < 10000; i++) { | |
var myCat = new Cat(); | |
j += myCat.makeSound(); | |
} | |
var endTime = new Date().getTime(); | |
console.log(j); | |
console.log(endTime - startTime); | |
/* ]]> */ | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment