Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
Chrome 52
Mac OS X 10.11.6
Other
8 years ago
Test name Executions per second
Explicit call 1224442.2 Ops/sec
Apply call 994995.6 Ops/sec
Apply with arguments call 401359.4 Ops/sec
Script Preparation code:
x
 
function wrapExplicit(fn) {
  return function(a1, a2, a3) {
    return fn.call(this, this, a1, a2, a3)
  }
}
function wrapApply(fn) {
  return function() {
    var args = [this]
    for (let i = 0, len = arguments.length; i < len; i++) {
      args[i + 1] = arguments[i]
    }
    return fn.apply(this, args)
  }
}
function wrapApplyWithArguments(fn) {
  return function() {
    return fn.apply(this, [this].concat(arguments))
  }
}
function fn(thisArg, a1, a2, a3) {
  thisArg.result = a1 + a2 + a3
}
var explicitCall = { fn: wrapExplicit(fn) }
var applyCall = { fn: wrapApply(fn) }
var applyWithArgumentsCall = { fn: wrapApplyWithArguments(fn) }
Tests:
  • Explicit call

     
    explicitCall.fn(Math.random(), Math.random(), Math.random())
  • Apply call

     
    applyCall.fn(Math.random(), Math.random(), Math.random())
  • Apply with arguments call

     
    applyWithArgumentsCall.fn(Math.random(), Math.random(), Math.random())