test-getter

JavaScript performance comparison

Test case created by Kriekkop

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const test1 = {
    sheet: {
       3: { id: {attr: {key: 3}}}
    },
    data: {
       sheet: 3
    }
  };
  test1.data.sheet = test1.sheet[3];
  test1.sheet[3] = {id: {attr: {key: 4}}};
  
  
  const test2 = {
    sheet: {
       3: { id: {attr: {key: 3}}}
    },
    data: {
       sheet: 3
    }
  };
  Object.defineProperty(test2.data, 'sheet', {get: () => {
    return test2.sheet[3];
  }})
  test2.sheet[3] = {id: {attr: {key: 4}}};
  
  
  const test3 = {
    sheet: {
       3: { id: {attr: {key: 3}}}
    },
    data: {
       sheet: 3
    }
  };
  test3.data.sheet = Reflect.get(test3.sheet, 3);
  test3.sheet[3] = {id: {attr: {key: 4}}};
  
  
  const test4 = {
    sheet: [],
    data: {
       sheet: 3
    }
  };
  test4.sheet[3] = { id: {attr: {key: 3}}};
  
  test4.data.sheet = test4.sheet[3];
  test4.sheet[3] = {id: {attr: {key: 4}}};
  
  
  const test5 = {
    sheet: [],
    data: {
      sheet: {ref: 'sheet', key: 3}
      }
  };
  
  test5.sheet[3] = { id: {attr: {key: 3}}};
  
  test5.data.sheet = new Proxy(test5.data.sheet, {
    get(target, prop, receiver) {
      return Reflect.get(test5.sheet[3], prop);
    }
  });
  test5.sheet[3] = {id: {attr: {key: 4}}};
  
  
  
  const getObject = (id, ct_key) => {
    return test5[ct_key][id];
  }; 
  
  
  
  const test6 = {
    sheet: {
       3: { id: {attr: {key: 3}}}
    },
    data: {
    }
  };
  
  
  const getObjeeee = (...args) => {
     return () => {
       Reflect.get(args[0], args[1]);
     }
   }; 
  
  Object.defineProperty(test6.data, 'sheet', {get: getObjeeee(test6.sheet, 3)})
  
  test6.sheet[3] = {id: {attr: {key: 4}}};

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
direct access
if (test1.data.sheet.id.attr.key !== 3) {
 console.log('test1', test1.data.sheet.id.attr.key);
};
pending…
functioned
if (test2.data.sheet.id.attr.key !== 4) {
 console.log('test2', test2.data.sheet.id.attr.key);
};
pending…
reflect
if (test3.data.sheet.id.attr.key !== 3) {
 console.log('test3', test3.data.sheet.id.attr.key);
};
pending…
array
if (test4.data.sheet.id.attr.key !== 3) {
 console.log('test4', test4.data.sheet.id.attr.key);
};
pending…
proxy
if (test5.data.sheet.id.attr.key !== 4) {
 console.log('test5', test5.data.sheet.id.attr.key);
};
pending…
static function
if (getObject(3, 'sheet').id.attr.key !== 4) {
 console.log('getusertest', getUser(3, 'sheet').id.attr.key);
};
pending…
static function in get met closure
if (test6.data.sheet.id.attr.key !== 4) {
 console.log('test6', test6.data.sheet.id.attr.key);
};
pending…

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

Compare results of other browsers

0 Comments