Object Literal Access VS Instance Access

JavaScript performance comparison

Test case created by whzx5byb

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function C(obj) { return class A {
    constructor() {
      var s = new Array(65536).fill(0);
      for (var i in obj) {
        if (obj.hasOwnProperty(i)) {
          Object.defineProperty(this, i, {get: function() {return this.foo}})
        }
      }
      for (var j in s) {
        Object.defineProperty(this, j, {get: function() {return 0}});
      }
      this.foo = 2;
    }
  }}
  
  var p = {foo: 3, get bar() { return this.foo}};
  var r = Object.create(p);
    
  
  class B {
        constructor() {
          this['foo'] = 2;
        }
        get bar() { return this.foo; }
      }
  
  const a1 = p;
  //const aa = C();
  const a2 = new (C({bar: 111}));
  let s = 0;

};
</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
Object Literal Access
s += a1.bar;
pending…
Instance Access
s += a2.bar;
pending…

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

0 Comments