Native bind vs jQuery.proxy vs Underscore bind

JavaScript performance comparison

Revision 9 of this test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js">
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/0.8.1/lodash.min.js">
</script>
<script>
  var lodash = _.noConflict();
</script>
<script>
Benchmark.prototype.setup = function() {
    var t1 = (function(x) {
      return this + x;
    }).bind(1);
    var t2 = jQuery.proxy(function(x) {
      return this + x;
    }, 1);
    var t3 = _.bind(function(x) {
      return this + x;
    }, 1);
   
    var t5 = lodash.bind(function(x) {
      return this + x;
    }, 1);
   
    var bar = function(x) {
        return this + x;
        };
    var t4 = function(x) {
        return bar.call(1, x);
        }
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Native bind
t1(1);
pending…
jQuery.proxy
t2(1)
pending…
Underscore.js bind
t3(1)
pending…
Without bind
t4(1)
pending…
lodash
t5(1)
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