Script Preparation code:
x
 
function wrap(fn) {
  // fast path if arity < 4, slow path if not
  switch (fn.length) {
    case 0:
      return function() {
        return fn.call(this)
      }
    case 1:
      return function() {
        return fn.call(this, this)
      }
    case 2:
      return function(a1) {
        return fn.call(this, this, a1)
      }
    case 3:
      return function(a1, a2) {
        return fn.call(this, this, a1, a2)
      }
    case 4:
      return function(a1, a2, a3) {
        return fn.call(this, this, a1, a2, a3)
      }
    default:
      return function() {
        const args = [this]
        for (let i = 0, len = arguments.length; i < len; i++) {
          args[i + 1] = arguments[i]
        }
        return fn.apply(this, args)
      }
  }
}
var f0 = wrap(function() { console.log(Date.now()) })
var f1 = wrap(function(a) { console.log(Date.now(), a) })
var f2 = wrap(function(a, b) { console.log(Date.now(), a, b) })
var f3 = wrap(function(a, b, c) { console.log(Date.now(), a, b, c) })
var f4 = wrap(function(a, b, c, d) { console.log(Date.now(), a, b, c, d) })
var f5 = wrap(function(a, b, c, d, e) { console.log(Date.now(), a, b, c, d, e) })
Tests:
  • With 0 parameter

     
    f0()
  • With 1 parameter

     
    f1(Date.now)
  • With 2 parameters

     
    f2(Date.now, Date.now + 1)
  • With 3 parameters

     
    f3(Date.now, Date.now + 1, Date.now + 2)
  • With 4 parameters

     
    f4(Date.now, Date.now + 1, Date.now + 2, Date.now + 3)
  • With 5 parameters

     
    f5(Date.now, Date.now + 1, Date.now + 2, Date.now + 3, Date.now + 4)
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    With 0 parameter
    With 1 parameter
    With 2 parameters
    With 3 parameters
    With 4 parameters
    With 5 parameters

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 8 years ago)
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 on Mac OS X 10.11.6
View result in a separate tab
Test name Executions per second
With 0 parameter 34706.9 Ops/sec
With 1 parameter 34291.7 Ops/sec
With 2 parameters 29877.6 Ops/sec
With 3 parameters 29267.1 Ops/sec
With 4 parameters 22543.0 Ops/sec
With 5 parameters 22863.7 Ops/sec