Skip to content

Instantly share code, notes, and snippets.

@greut
Created April 4, 2009 12:52
Show Gist options
  • Select an option

  • Save greut/90199 to your computer and use it in GitHub Desktop.

Select an option

Save greut/90199 to your computer and use it in GitHub Desktop.
$ 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
// 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