array.forEach(fn.bind(context) vs. array.forEach(fn, context); (v5)

Revision 5 of this benchmark created on


Preparation HTML

<script>
  function MySupaObject() {
    this.numbers = [0,1,2,3,4,5,6,7,8,9];
    this.multiplier = 2;
  }
  MySupaObject.prototype.multWithContextParameter = function() {
    return this.numbers.map(function(number) {
      return number * this.multiplier;
    }, this);
  };
  MySupaObject.prototype.multWithBindThis = function() {
    return this.numbers.map(function(number) {
      return number * this.multiplier;
    }.bind(this));
  };
  var myObj = new MySupaObject();
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
forEach(fn.bind(ctx))
myObj.multWithContextParameter();
ready
forEach(fn, ctx)
myObj.multWithBindThis();
ready
var blah = 0;
testArray.forEach(function(num) {
  blah += num;
});
ready

Revisions

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