Function.bind performance (v2)

Revision 2 of this benchmark created on


Preparation HTML

<script>
var native = function() {
    this.label = "";
    this.stringAppend = function() {
        this.label = "hello" + "world";
    }
}

var proto = function() {
    this.label = "";
}

proto.prototype.stringAppend = function() {
    this.label = "hello" + "world";
}

var bind = function() {
    this.label = "";
    this.stringAppend = function() {
        this.label = "hello" + "world";
    }.bind(this);
}

var closure = function() {
    this.label = "";
    var self = this;
    self.stringAppend = function() {
        self.label = "hello" + "world";
    }
}

// test function and context
  var testcxt = {},
      testarg1 = 'test',
      testarg2 = {},
      testarg3 = 1,
      testarg4 = {},
      testfunc = function() {
    if (this !== testcxt || arguments.length != 4) throw new Error('failed');
      };

  
  var first = native.stringAppend();
  var second = proto.stringAppend();
  var third = closure.stringAppend();
  var native = bind.stringAppend();


</script>

Test runner

Ready to run.

Testing in
TestOps/sec
First
first(testarg3, testarg4)
ready
Second
second(testarg3, testarg4)
ready
Third
third(testarg3, testarg4)
ready
Native
native(testarg3, testarg4)
ready

Revisions

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