arrow functions vs bind vs self (instantiation)

Benchmark created by Kevin Ennis on


Description

See how long it takes to create (but not execute).

Setup

var obj = { 
    
      val: 4,
    
      bind: function() {
        return function() {
          return this.val * this.val;
        }.bind( this ); 
      },
    
      self: function() {
        var self = this;
        return function() {
          return self.val * self.val;
        };
      },
    
      arrow: function() {
        return () => this.val * this.val;
      }
      
    };

Test runner

Ready to run.

Testing in
TestOps/sec
bind
obj.bind();
ready
self
obj.self();
ready
arrow
obj.arrow();
ready

Revisions

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