apply vs call vs invoke (v8)

Revision 8 of this benchmark created by JulienW on


Setup

var obj = {
      fn: function(a,b) {return a + b; }
    };
    
    var fn = obj.fn,
        fnJsBound = jsBind(obj, fn),
        fnBound = function() {};
    
    if (fn.bind) {
      fnBound = fn.bind(obj);
    }
    
    function jsBind(self, fn) {
      return function() {
        return fn.apply(self, arguments);
       };
    }

Test runner

Ready to run.

Testing in
TestOps/sec
bind (native) (run if Function.prototype.bind exists)
fnBound(1, 2);
ready
bind (js)
fnJsBound(1, 2);
ready
direct invoke
fn(1, 2);
ready
direct invoke on obj
obj.fn(1, 2);
ready

Revisions

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