Array vs Object read/write

JavaScript performance comparison

Revision 2 of this test case created by 1Pupik1989

Info

Test Object/Array access

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var obj = {
      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 arr = [
      0,0,0,0,
      0,0,0,0,
      0,0,0,0,
      0,0,0,0
    ];
   
    var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q;
};
</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
b = obj.m0;
c = obj.m1;
d = obj.m2;
e = obj.m3;
f = obj.m4;
g = obj.m5;
h = obj.m6;
i = obj.m7;
j = obj.m8;
k = obj.m9;
l = obj.m10;
m = obj.m11;
n = obj.m12;
o = obj.m13;
p = obj.m14;
q = obj.m15;
pending…
Array read
b = arr[0];
c = arr[1];
d = arr[2];
e = arr[3];
f = arr[4];
g = arr[5];
h = arr[6];
i = arr[7];
j = arr[8];
k = arr[9];
l = arr[10];
m = arr[11];
n = arr[12];
o = arr[13];
p = arr[14];
q = arr[15];
pending…
Object write
obj.m0 = 1;
obj.m1 = 2;
obj.m2 = 3;
obj.m3 = 4;
obj.m4 = 0;
obj.m5 = 5;
obj.m6 = 6;
obj.m7 = 7;
obj.m8 = 0;
obj.m9 = 0;
obj.m10 = 8;
obj.m11 = 9;
obj.m12 = 0;
obj.m13 = 0;
obj.m14 = 0;
obj.m15 = 10;
pending…
Array write
arr[0] = 1;
arr[1] = 2;
arr[2] = 3;
arr[3] = 4;
arr[4] = 0;
arr[5] = 5;
arr[6] = 6;
arr[7] = 7;
arr[8] = 0;
arr[9] = 0;
arr[10] = 8;
arr[11] = 9;
arr[12] = 0;
arr[13] = 0;
arr[14] = 0;
arr[15] = 10;
pending…
Entry into a new Object
obj = {
  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
arr = [
  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