Created
April 4, 2009 12:52
-
-
Save greut/90199 to your computer and use it in GitHub Desktop.
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
| $ js -v | |
| JavaScript-C 1.8.0 pre-release 1 2007-10-03 | |
| $ js speed.js | |
| 1 childs: 0 | |
| 10 childs: 1 | |
| 100 childs: 3 | |
| 1000 childs: 40 | |
| 10000 childs: 217 | |
| 100000 childs: 5692 |
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
| // creating a deep prototypal chain (inheritance) | |
| function test(n) { | |
| var mom = function(){}; | |
| mom.prototype.name = "mom"; | |
| for(var i=0;i<n;i++) { | |
| var son = function() {}; | |
| son.prototype = new mom; | |
| mom = son; | |
| } | |
| return mom; | |
| } | |
| function speed(fn, n) { | |
| var class = fn(), | |
| obj = new class(), | |
| now = new Date(); | |
| for(var i=0;i<n;i++) { | |
| obj.name == "mom"; | |
| } | |
| return new Date() - now; | |
| } | |
| for(var i=0;i<6;i++){ | |
| var quantity = Math.pow(10, i); | |
| print(quantity+" childs:\t" + speed(function() { return test(quantity) }, 1000)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment