Object.create vs Crockford vs Constructor vs Cornford
JavaScript performance comparison
Preparation code
<script>
var sharedPrototype = {
one: function() {
return 1;
},
two: function() {
return 2;
},
three: function() {
return 3;
}
};
var crockfordCreate = function(proto) {
var f = function() {};
f.prototype = proto;
return new f();
};
var Constructor = function() {};
Constructor.prototype = sharedPrototype;
var cornfordCreate = (function() {
var f = function() {};
return function(proto) {
f.prototype = proto;
return new f();
};
})();
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Object.create() |
|
pending… |
Crockford Create |
|
pending… |
Constructor |
|
pending… |
Proto |
|
pending… |
Cornford Create |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published by Jeremy Ashkenas
- Revision 9: published
- Revision 10: published by Jeremy Ashkenas
- Revision 11: published
- Revision 12: published by Vjeux
- Revision 15: published
- Revision 16: published by Peter Michaux
- Revision 17: published by Peter Michaux
- Revision 18: published by Kevin Gadd
- Revision 19: published by Brian Cavalier
- Revision 20: published by Rob Friesel
- Revision 21: published
- Revision 22: published by Mark Bradley
- Revision 23: published
- Revision 24: published
- Revision 25: published
- Revision 26: published
- Revision 27: published by Scott Sauyet
- Revision 29: published
- Revision 30: published by Leo Cavalcante
- Revision 31: published
- Revision 32: published
- Revision 33: published by A. Matías Quezada
- Revision 37: published
- Revision 38: published
- Revision 39: published
- Revision 40: published
- Revision 42: published by frooble
1 comment
Version 17 is wrong.