Array vs Object read/write

JavaScript performance comparison

Test case created by 1Pupik1989

Info

Test Object/Array access

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var o = {
      m0:0,m1:0,m2:0,m3:0,
      m4:0,m5:0,m6:0,m7:0,
      m8:0,m9:0,m10:0,m11:0,
      m12:0,m13:0,m14:0,m15:0
    };
   
    var a = [
      0,0,0,0,
      0,0,0,0,
      0,0,0,0,
      0,0,0,0
    ];
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Object read
o.m0;
o.m1;
o.m2;
o.m3;
o.m4;
o.m5;
o.m6;
o.m7;
o.m8;
o.m9;
o.m10;
o.m11;
o.m12;
o.m13;
o.m14;
o.m15;
pending…
Array read
a[0];
a[1];
a[2];
a[3];
a[4];
a[5];
a[6];
a[7];
a[8];
a[9];
a[10];
a[11];
a[12];
a[13];
a[14];
a[15];
pending…
Object write
o.m0 = 1;
o.m1 = 2;
o.m2 = 3;
o.m3 = 4;
o.m4 = 0;
o.m5 = 5;
o.m6 = 6;
o.m7 = 7;
o.m8 = 0;
o.m9 = 0;
o.m10 = 8;
o.m11 = 9;
o.m12 = 0;
o.m13 = 0;
o.m14 = 0;
o.m15 = 10;
pending…
Array write
a[0] = 1;
a[1] = 2;
a[2] = 3;
a[3] = 4;
a[4] = 0;
a[5] = 5;
a[6] = 6;
a[7] = 7;
a[8] = 0;
a[9] = 0;
a[10] = 8;
a[11] = 9;
a[12] = 0;
a[13] = 0;
a[14] = 0;
a[15] = 10;
pending…
Entry into a new Object
o = {
  m0:1,m1:2,m2:3,m3:4,
  m4:0,m5:5,m6:6,m7:7,
  m8:0,m9:0,m10:8,m11:9,
  m12:0,m13:0,m14:0,m15:10
};
pending…
Entry into a new Array
a = [
  1,2,3,4,
  0,5,6,7,
  0,0,8,9,
  0,0,0,10
];
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:

0 comments

Add a comment