Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Chrome 121
Mac OS X 10.15.7
Desktop
11 months ago
Test name Executions per second
class without declared fields 31189.8 Ops/sec
class with declared fields 5321.5 Ops/sec
Script Preparation code:
AخA
 
// classes declared here can't be accessed in test cases for some reason...
Tests:
  • class without declared fields

    x
     
    class X {
      constructor(foo, bar, baz) {
        this.foo = foo;
        this.bar = bar;
        this.baz = baz;
      }
      sum() {
        return this.foo + this.bar + this.baz;
      }
    }
    let i = 1000;
    let y = 0;
    while (i--) {
      let x = new X(1, 2, 3);
      y += x.foo + x.bar + x.baz;
      y += x.sum();
    }
    return y;
  • class with declared fields

     
    class X {
      foo;
      bar;
      baz;
      constructor(foo, bar, baz) {
        this.foo = foo;
        this.bar = bar;
        this.baz = baz;
      }
      sum() {
        return this.foo + this.bar + this.baz;
      }
    }
    let i = 1000;
    let y = 0;
    while (i--) {
      let x = new X(1, 2, 3);
      y += x.foo + x.bar + x.baz;
      y += x.sum();
    }
    return y;