Artificial vs. Native Bind

JavaScript performance comparison

Revision 3 of this test case created

Info

Determine performance gains of native bind. Note: artificial bind doesn't support partial application.

Preparation code

<script>
  function artificial_bind(fn, context) {
   return function() {
    return fn.apply(context);
   }
  }

  var bind;

if(Function.prototype.bind){
        bind = function(fn, context){
                var prependArgs = Array.prototype.slice.call(arguments, 2);                            
                return fn.bind(context, prependArgs);
        };
}
  function test(arg) {
   var i;
   for (i = 0; i < 1000; i++) {
    arg += i;
   }
   this.lol = arg;

  }
</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
Artificial
artificial_bind(test, {})(1337)
pending…
Native
bind(test,{})(1337);
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