literal vs new (v10)

Revision 10 of this benchmark created on


Preparation HTML

<script>
  var o;
  
  if (!Object.create) {
    Object.create = function (o) {
      var f = function() { };
      f.prototype = o;
      return new f;
    }
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
new
o = new Array(7);
for (var i = 0; i < 7; i++) {
  o[i] = 'data';
}
ready
literal
o = [];
for (var i = 0; i < 7; i++) {
  o.push('data');
}
ready
invoke
o = new Array();
ready
create
o = Object.create(Array.prototype);
ready
zero length
o = new Array(0);
ready
without new
o = Array();
ready
new with data
o = new Array("data");
ready
array with data
o = Array("data");
ready
literal with data
o = ["data"];
ready
literal with length
o = [];
o.length = 7;
for (var i = 0; i < 7; i++) {
  o[i] = 'data';
}
ready

Revisions

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