call vs apply with arguments

JavaScript performance comparison

Revision 3 of this test case created

Info

The test is to see the performance difference in call vs apply when using inheritance in Javascript to call a superclass's function.

Preparation code

<script>
  function SuperClass(a, b, c) {};
  SuperClass.prototype = {
    constructor: SuperClass
  };

  function CallClass() {
    SuperClass.prototype.constructor.call(this, true, 2, "three");
  }

  function ApplyClass() {
    SuperClass.prototype.constructor.apply(this, [true, 2, "three"]);
  }

  function ApplyWithArgumentsClass() {
    SuperClass.prototype.constructor.apply(this, arguments);
  }
</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
call() with 3 args
var callInstance = new CallClass();
pending…
apply() with 3 args
var applyInstance = new ApplyClass();
pending…
apply() with arguments
var applyWithArgsInstance = new ApplyWithArgumentsClass(true, 2, "three");
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