Object properties and array items

JavaScript performance comparison

Revision 9 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var obj = {
      x: 10,
      y: 15,
      z: 20
    };
   
    var _obj = {};
   
    var a = 10;
    var b = 15;
    var c = 20;
   
    var arr = [10, 15, 20];
   
    var f32 = new Float32Array(arr);
    var f64 = new Float64Array(arr);
   
    var i8 = new Int8Array(arr);
    var i16 = new Int16Array(arr);
    var i32 = new Int32Array(arr);
   
    var ui8 = new Uint8Array(arr);
    var ui8c = new Uint8ClampedArray(arr);
    var ui16 = new Uint16Array(arr);
    var ui32 = new Uint32Array(arr);
   
   
    var _arr = new Array(3);
   
    var _f32 = new Float32Array(3);
    var _f64 = new Float64Array(3);
   
    var _i8 = new Int8Array(3);
    var _i16 = new Int16Array(3);
    var _i32 = new Int32Array(3);
   
    var _ui8 = new Uint8Array(3);
    var _ui8c = new Uint8ClampedArray(3);
    var _ui16 = new Uint16Array(3);
    var _ui32 = new Uint32Array(3);
};
</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 properties
var x = obj.x;
var y = obj.y;
var z = obj.z;
pending…
Array items
var x = arr[0];
var y = arr[1];
var z = arr[2];
pending…
Object property names
var x = obj['x'];
var y = obj['y'];
var z = obj['z'];
pending…
Float32Array items
var x = f32[0];
var y = f32[1];
var z = f32[2];
pending…
Float64Array items
var x = f64[0];
var y = f64[1];
var z = f64[2];
pending…
Int8Array items
var x = i8[0];
var y = i8[1];
var z = i8[2];
pending…
Int16Array items
var x = i16[0];
var y = i16[1];
var z = i16[2];
pending…
Int32Array items
var x = i32[0];
var y = i32[1];
var z = i32[2];
pending…
Uint8Array items
var x = ui8[0];
var y = ui8[1];
var z = ui8[2];
pending…
Uint8ClampedArray items
var x = ui8c[0];
var y = ui8c[1];
var z = ui8c[2];
pending…
Uint16Array items
var x = ui16[0];
var y = ui16[1];
var z = ui16[2];
pending…
Uint32Array items
var x = ui32[0];
var y = ui32[1];
var z = ui32[2];
pending…
write Object properties
_obj.a = a;
_obj.b = b;
_obj.c = c;
pending…
write Array items
_arr[0] = a;
_arr[1] = b;
_arr[2] = c;
pending…
write Object property names
_obj['a'] = a;
_obj['b'] = b;
_obj['c'] = c;
pending…
write Float32Array items
_f32[0] = a;
_f32[1] = b;
_f32[2] = c;
pending…
write Float64Array items
_f64[0] = a;
_f64[1] = b;
_f64[2] = c;
pending…
write Int8Array items
_i8[0] = a;
_i8[1] = b;
_i8[2] = c;
pending…
write Int16Array items
_i16[0] = a;
_i16[1] = b;
_i16[2] = c;
pending…
write Int32Array items
_i32[0] = a;
_i32[1] = b;
_i32[2] = c;
pending…
write Uint8Array items
_ui8[0] = a;
_ui8[1] = b;
_ui8[2] = c;
pending…
write Uint8ClampedArray items
_ui8c[0] = a;
_ui8c[1] = b;
_ui8c[2] = c;
pending…
write Uint16Array items
_ui16[0] = a;
_ui16[1] = b;
_ui16[2] = c;
pending…
write Uint32Array items
_ui32[0] = a;
_ui32[1] = b;
_ui32[2] = c;
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