Array vs Object read/write

JavaScript performance comparison

Revision 3 of this test case created by 1Pupik1989

Info

Test Object/Array access

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var array = [
      0,0,0,0,
      0,0,0,0,
      0,0,0,0,
      0,0,0,0
    ];
    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 nativeArray = new Array(array);
    var int8Array = new Int8Array(array);
    var int16Array = new Int16Array(array);
    var int32Array = new Int32Array(array);
    var float32Array = new Float32Array(array);
    var float64Array = new Float64Array(array);
   
    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…
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 read
b = nativeArray[0]; c = nativeArray[1]; d = nativeArray[2]; e = nativeArray[3];
f = nativeArray[4]; g = nativeArray[5]; h = nativeArray[6]; i = nativeArray[7];
j = nativeArray[8]; k = nativeArray[9]; l = nativeArray[10]; m = nativeArray[11];
n = nativeArray[12]; o = nativeArray[13]; p = nativeArray[14]; q = nativeArray[15];
pending…
Array write
nativeArray[0] = 1; nativeArray[1] = 2; nativeArray[2] = 3; nativeArray[3] = 4;
nativeArray[4] = 0; nativeArray[5] = 5; nativeArray[6] = 6; nativeArray[7] = 7;
nativeArray[8] = 0; nativeArray[9] = 0; nativeArray[10] = 8; nativeArray[11] = 9;
nativeArray[12] = 0; nativeArray[13] = 0; nativeArray[14] = 0; nativeArray[15] = 10;
pending…
Int8Array read
b = int8Array[0]; c = int8Array[1]; d = int8Array[2]; e = int8Array[3];
f = int8Array[4]; g = int8Array[5]; h = int8Array[6]; i = int8Array[7];
j = int8Array[8]; k = int8Array[9]; l = int8Array[10]; m = int8Array[11];
n = int8Array[12]; o = int8Array[13]; p = int8Array[14]; q = int8Array[15];
pending…
Int8Array write
int8Array[0] = 1; int8Array[1] = 2; int8Array[2] = 3; int8Array[3] = 4;
int8Array[4] = 0; int8Array[5] = 5; int8Array[6] = 6; int8Array[7] = 7;
int8Array[8] = 0; int8Array[9] = 0; int8Array[10] = 8; int8Array[11] = 9;
int8Array[12] = 0; int8Array[13] = 0; int8Array[14] = 0; int8Array[15] = 10;
pending…
literal Array read
b = array[0]; c = array[1]; d = array[2]; e = array[3];
f = array[4]; g = array[5]; h = array[6]; i = array[7];
j = array[8]; k = array[9]; l = array[10]; m = array[11];
n = array[12]; o = array[13]; p = array[14]; q = array[15];
pending…
literal Array write
array[0] = 1; array[1] = 2; array[2] = 3; array[3] = 4;
array[4] = 0; array[5] = 5; array[6] = 6; array[7] = 7;
array[8] = 0; array[9] = 0; array[10] = 8; array[11] = 9;
array[12] = 0; array[13] = 0; array[14] = 0; array[15] = 10;
pending…
Int16Array read
b = int16Array[0]; c = int16Array[1]; d = int16Array[2]; e = int16Array[3];
f = int16Array[4]; g = int16Array[5]; h = int16Array[6]; i = int16Array[7];
j = int16Array[8]; k = int16Array[9]; l = int16Array[10]; m = int16Array[11];
n = int16Array[12]; o = int16Array[13]; p = int16Array[14]; q = int16Array[15];
pending…
Int16Array write
int16Array[0] = 1; int16Array[1] = 2; int16Array[2] = 3; int16Array[3] = 4;
int16Array[4] = 0; int16Array[5] = 5; int16Array[6] = 6; int16Array[7] = 7;
int16Array[8] = 0; int16Array[9] = 0; int16Array[10] = 8; int16Array[11] = 9;
int16Array[12] = 0; int16Array[13] = 0; int16Array[14] = 0; int16Array[15] = 10;
pending…
Int32Array read
b = int32Array[0]; c = int32Array[1]; d = int32Array[2]; e = int32Array[3];
f = int32Array[4]; g = int32Array[5]; h = int32Array[6]; i = int32Array[7];
j = int32Array[8]; k = int32Array[9]; l = int32Array[10]; m = int32Array[11];
n = int32Array[12]; o = int32Array[13]; p = int32Array[14]; q = int32Array[15];
pending…
Int32Array write
int32Array[0] = 1; int32Array[1] = 2; int32Array[2] = 3; int32Array[3] = 4;
int32Array[4] = 0; int32Array[5] = 5; int32Array[6] = 6; int32Array[7] = 7;
int32Array[8] = 0; int32Array[9] = 0; int32Array[10] = 8; int32Array[11] = 9;
int32Array[12] = 0; int32Array[13] = 0; int32Array[14] = 0; int32Array[15] = 10;
pending…
Float32Array read
b = float32Array[0]; c = float32Array[1]; d = float32Array[2]; e = float32Array[3];
f = float32Array[4]; g = float32Array[5]; h = float32Array[6]; i = float32Array[7];
j = float32Array[8]; k = float32Array[9]; l = float32Array[10]; m = float32Array[11];
n = float32Array[12]; o = float32Array[13]; p = float32Array[14]; q = float32Array[15];
pending…
Float32Array write
float32Array[0] = 1; float32Array[1] = 2; float32Array[2] = 3; float32Array[3] = 4;
float32Array[4] = 0; float32Array[5] = 5; float32Array[6] = 6; float32Array[7] = 7;
float32Array[8] = 0; float32Array[9] = 0; float32Array[10] = 8; float32Array[11] = 9;
float32Array[12] = 0; float32Array[13] = 0; float32Array[14] = 0; float32Array[15] = 10;
pending…
Float64Array read
b = float64Array[0]; c = float64Array[1]; d = float64Array[2]; e = float64Array[3];
f = float64Array[4]; g = float64Array[5]; h = float64Array[6]; i = float64Array[7];
j = float64Array[8]; k = float64Array[9]; l = float64Array[10]; m = float64Array[11];
n = float64Array[12]; o = float64Array[13]; p = float64Array[14]; q = float64Array[15];
pending…
Float64Array write
float64Array[0] = 1; float64Array[1] = 2; float64Array[2] = 3; float64Array[3] = 4;
float64Array[4] = 0; float64Array[5] = 5; float64Array[6] = 6; float64Array[7] = 7;
float64Array[8] = 0; float64Array[9] = 0; float64Array[10] = 8; float64Array[11] = 9;
float64Array[12] = 0; float64Array[13] = 0; float64Array[14] = 0; float64Array[15] = 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