bind vs emulate

JavaScript performance comparison

Revision 11 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function Emulated () {
      var emulated = this
      this.test = function (one, two) {
        return emulated._test(one, two)
      }
    }
   
    Emulated.prototype._test = function (one, two) { return one + two }
   
    function Normal () {
      this.test = this._test.bind(this)
    }
   
    Normal.prototype._test = function (one, two) {
      return one + two
    }
   
    var emulated = new Emulated()
    var normal   = new Normal()
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
control
normal._test(1, 2)
pending…
string
normal['_test'](1, 2)
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment