spread apply vs apply

JavaScript performance comparison

Revision 16 of this test case created by Spread Apply vs Apply

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function Obj() {
          var that = "that";
    }
    Obj.prototype.target = function(test) {
       return test;
    };
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
apply
var val = ["1", "2", "3"];
Obj.prototype.target.apply(this, val);  
pending…
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;
}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment