spread apply vs apply (v17)

Revision 17 of this benchmark created on


Setup

function Obj() {
          var that = "that";
    }
    Obj.prototype.target = function(test) {
       return test;
    };

Test runner

Ready to run.

Testing in
TestOps/sec
apply
var val = ["1", "2", "3"];
Obj.prototype.target.apply(this, val);  
ready
modified apply
var val = ["1", "2", "3"];

switch(val.length)
{
case 0:
  Obj.prototype.target.call(this);
  break;
case 1:
  Obj.prototype.target.call(this, val[0]);
  break;
case 2:
  Obj.prototype.target.call(this, val[0], val[1]);
  break;
case 3:
  Obj.prototype.target.call(this, val[0], val[1], val[2]);
  break;
default:  Obj.prototype.target.apply(this, val);
}
ready
var val = ["1", "2", "3"];

switch(val.length)
{
case 0:
  Obj.prototype.target();
  break;
case 1:
  Obj.prototype.target(val[0]);
  break;
case 2:
  Obj.prototype.target(val[0], val[1]);
  break;
case 3:
  Obj.prototype.target(val[0], val[1], val[2]);
  break;
default: Obj.prototype.target.apply(this, val);
}
ready
var val = ["1", "2", "3"];
var l = val.length;

if (!val || !l) { Obj.prototype.target(); }

switch(val.length)
{
case 0:
  Obj.prototype.target();
  break;
case 1:
  Obj.prototype.target(val[0]);
  break;
case 2:
  Obj.prototype.target(val[0], val[1]);
  break;
case 3:
  Obj.prototype.target(val[0], val[1], val[2]);
  break;
default:  Obj.prototype.target.apply(this, val);
}
ready

Revisions

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