Skip to content

Instantly share code, notes, and snippets.

@padolsey
Created November 27, 2009 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save padolsey/244166 to your computer and use it in GitHub Desktop.
Save padolsey/244166 to your computer and use it in GitHub Desktop.
/// Run this code in any browser
function RegularConstructor () {
}
RegularConstructor.prototype = {
meth1: function(){},
meth2: function(){},
meth3: function(){},
meth4: function(){},
meth5: function(){},
meth6: function(){},
meth7: function(){},
meth8: function(){},
meth9: function(){}
};
function crockfordsIdea () {
var inst = {
meth1: function(){},
meth2: function(){},
meth3: function(){},
meth4: function(){},
meth5: function(){},
meth6: function(){},
meth7: function(){},
meth8: function(){},
meth9: function(){}
};
return inst;
}
var n = +new Date;
for (var i = 0; i < 10000; ++i ) {
crockfordsIdea();
}
alert('crockfordsIdea :' + (+new Date - n) + 'ms');
var n = +new Date;
for (var i = 0; i < 10000; ++i) {
new RegularConstructor();
}
alert('RegularConstructor :' + (+new Date - n) + 'ms');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment