bind vs closure (v21)

Revision 21 of this benchmark created on


Setup

function Foo(x) {
    this._x = x;
  }
  
  Foo.prototype.getValue = function() {
    return this._x + 5;
  };
  
  var self = new Foo(7);
  
  var boundFn = (function(a, b) {
    return this.getValue() + a + b;
  }).bind(self);
  
  var selfFn = function(a, b) {
    return self.getValue() + a + b;
  };

Test runner

Ready to run.

Testing in
TestOps/sec
bind()
for (var i = 0; i < 1000000; i++)
    boundFn(i, 99)
ready
self
for (var i = 0; i < 1000000; i++)
    selfFn(i, 99);
ready

Revisions

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