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 counter = 0
var f0 = wrap(function() { return counter++ })
var f1 = wrap(function(a) { return (counter += a) })
var f2 = wrap(function(a, b) { return (counter += (a + b)) })
var f3 = wrap(function(a, b, c) { return (counter += (a + b + c)) })
var f4 = wrap(function(a, b, c, d) { return (counter += (a + b + c + d)) })
var f5 = wrap(function(a, b, c, d, e) { return (counter += (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 2810095.5 Ops/sec
With 1 parameter 445385.5 Ops/sec
With 2 parameters 216158.5 Ops/sec
With 3 parameters 146745.9 Ops/sec
With 4 parameters 31633.5 Ops/sec
With 5 parameters 2730.4 Ops/sec