object.create vs new vs literal

Benchmark created by Grant Kiely on


Preparation HTML

<script>
var Test2 = {
   val: 5,
   func: function(){
    return 3+3 + "";
  }
}
function Test3(val){
  this.test = val
}
Test3.prototype.func = function(){
return 3+3+"";
}
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Literal
var Test = {
   val: 5,
   func: function(){
    return 3+3 + "";
  }
}
ready
New setup
function Test(val){
  this.test = val
}
Test.prototype.func = function(){
return 3+3+"";
}
ready
object.create
var test2 = Object.create(Test2);
ready
new create
var test3 = new Test3(2);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by Grant Kiely on