Arrow function vs bound function with 100 instances

Benchmark created by Nicolas Charpentier on


Setup

// Arrow function method
  const A = class A {
    constructor() {
      this.counter = 0;
  
      this.handleClick = () => {
        this.counter++;
      }
    }
  }
  
  // Binded function method
  const B = class B {
    constructor() {
      this.counter = 0;
      this.handleClick = this.handleClick.bind(this);
    }
    
    handleClick() {
      this.counter++;
    }
  }
  
  // Function method
  const C = class C {
    constructor() {
      this.counter = 0;
    }
    
    handleClick() {
      this.counter++;
    }
  }

Test runner

Ready to run.

Testing in
TestOps/sec
Arrow function
Array(100).fill({})
  .map(() => new A())
  .map(component => component.handleClick());
ready
Bound function
Array(100).fill({})
  .map(() => new B())
  .map(component => component.handleClick());
ready
Function
Array(100).fill({})
  .map(() => new C())
  .map(component => component.handleClick());
ready

Revisions

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

  • Revision 1: published by Nicolas Charpentier on