Object Creation

Benchmark created by adrianmcli on


Setup

let myClassObject;
  let myFuncObject1;
  let myFuncObject2;
  
  // using the `class` keyword
  class MyClassObject {
    constructor(initVal) {
      this.myVal = initVal;
    }
  
    set(x) {
      this.myVal = x;
    }
  }
  
  // using a function with `this`
  const makeObject1 = initVal => {
    return {
      myVal: initVal,
      set: function(x) {
        this.myVal = x;
      },
    };
  };
  
  // using a function without `this`
  const makeObject2 = initVal => {
    let myVal = initVal;
    return {
      get: function() {
        return myVal;
      },
      set: function(val) {
        myVal = val;
      },
    };
  };

Teardown



            delete myClassObject;
  delete myFuncObject1;
  delete myFuncObject2;
        
  

Test runner

Ready to run.

Testing in
TestOps/sec
ES2015 Classes
myClassObject = new MyClassObject(0)
ready
Function with this
myFuncObject1 = makeObject1(0)
ready
Function without this
myFuncObject2 = makeObject2(0)
ready

Revisions

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

  • Revision 1: published by adrianmcli on