Dot vs Square Brackets (v6)

Revision 6 of this benchmark created on


Setup

var testObj = {
        extra: 'properties',
        to: 'hinder',
        compiler: 'optimization',
        A: 'A',
        B: 'B',
        C: 'C',
        D: 'D',
        E: 'E',
        F: 'F',
        G: 'G',
        H: 'H',
        I: 'I',
        J: 'J',
        K: 'K',
        L: 'L',
        M: 'M',
        N: 'N',
        O: 'O',
        P: 'P',
        Q: 'Q',
        R: 'R',
        S: 'S',
        T: 'T',
        U: 'U',
        V: 'V',
        W: 'W',
        X: 'X',
        Y: 'Y',
        Z: 'Z',
        getA: function () { return this.A; },
        getB: function () { return this.B; },
        getC: function () { return this.C; },
        getD: function () { return this.D; },
        getE: function () { return this.E; },
        getF: function () { return this.F; },
        getG: function () { return this.G; },
        getH: function () { return this.H; },
        getI: function () { return this.I; },
        getJ: function () { return this.J; },
        getK: function () { return this.K; },
        getL: function () { return this.L; },
        getM: function () { return this.M; },
        getN: function () { return this.N; },
        getO: function () { return this.O; },
        getP: function () { return this.P; },
        getQ: function () { return this.Q; },
        getR: function () { return this.R; },
        getS: function () { return this.S; },
        getT: function () { return this.T; },
        getU: function () { return this.U; },
        getV: function () { return this.V; },
        getW: function () { return this.W; },
        getX: function () { return this.X; },
        getY: function () { return this.Y; },
        getZ: function () { return this.Z; }
    };
    
    var testObjGetters = [
    testObj.getA, testObj.getB, testObj.getC, testObj.getD, testObj.getE, testObj.getF, testObj.getG, testObj.getH, testObj.getI, testObj.getJ, testObj.getK, testObj.getL, testObj.getM, testObj.getN, testObj.getO, testObj.getP, testObj.getQ, testObj.getR, testObj.getS, testObj.getT, testObj.getU, testObj.getV, testObj.getW, testObj.getX, testObj.getY, testObj.getZ
    ];
    
    var getters = [
        function (obj) { return obj.A; },
        function (obj) { return obj.B; },
        function (obj) { return obj.C; },
        function (obj) { return obj.D; },
        function (obj) { return obj.E; },
        function (obj) { return obj.F; },
        function (obj) { return obj.G; },
        function (obj) { return obj.H; },
        function (obj) { return obj.I; },
        function (obj) { return obj.J; },
        function (obj) { return obj.K; },
        function (obj) { return obj.L; },
        function (obj) { return obj.M; },
        function (obj) { return obj.N; },
        function (obj) { return obj.O; },
        function (obj) { return obj.P; },
        function (obj) { return obj.Q; },
        function (obj) { return obj.R; },
        function (obj) { return obj.S; },
        function (obj) { return obj.T; },
        function (obj) { return obj.U; },
        function (obj) { return obj.V; },
        function (obj) { return obj.W; },
        function (obj) { return obj.X; },
        function (obj) { return obj.Y; },
        function (obj) { return obj.Z; }
    ];
    
    var gettersThis = [
        function () { return this.A; },
        function () { return this.B; },
        function () { return this.C; },
        function () { return this.D; },
        function () { return this.E; },
        function () { return this.F; },
        function () { return this.G; },
        function () { return this.H; },
        function () { return this.I; },
        function () { return this.J; },
        function () { return this.K; },
        function () { return this.L; },
        function () { return this.M; },
        function () { return this.N; },
        function () { return this.O; },
        function () { return this.P; },
        function () { return this.Q; },
        function () { return this.R; },
        function () { return this.S; },
        function () { return this.T; },
        function () { return this.U; },
        function () { return this.V; },
        function () { return this.W; },
        function () { return this.X; },
        function () { return this.Y; },
        function () { return this.Z; }
    ];
    
    var value = null;

Teardown


    if(value != 'Z') {
      throw new Error('test ' + this.name + ' did not run correctly, last value is ' + value + ' should be \'Z\'');
    }
  

Test runner

Ready to run.

Testing in
TestOps/sec
Dot Notation
var A = testObj.A;
var B = testObj.B;
var C = testObj.C;
var D = testObj.D;
var E = testObj.E;
var F = testObj.F;
var G = testObj.G;
var H = testObj.H;
var I = testObj.I;
var J = testObj.J;
var K = testObj.K;
var L = testObj.L;
var M = testObj.M;
var N = testObj.N;
var O = testObj.O;
var P = testObj.P;
var Q = testObj.Q;
var R = testObj.R;
var S = testObj.S;
var T = testObj.T;
var U = testObj.U;
var V = testObj.V;
var W = testObj.W;
var X = testObj.X;
var Y = testObj.Y;
var Z = testObj.Z;
value = testObj.Z;
ready
Square Brackets
var ary = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
for(var i = 0, size = 26; i < size; i++) {
   value = testObj[ary[i]];
}
ready
Anonymous Function Dot Notation
for(var i = 0, size = getters.length; i < size; i++) {
   value = getters[i](testObj);
}
ready
Anonymous Function Using 'this.'
for(var i = 0, size = gettersThis.length; i < size; i++) {
   value = gettersThis[i].call(testObj);
}
ready

Revisions

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