call vs apply with arguments
JavaScript performance comparison
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.
| Test | Ops/sec | |
|---|---|---|
call() with 3 args |
|
pending… |
apply() with 3 args |
|
pending… |
apply() with arguments |
|
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:
- Revision 1: published by Shane Tomlinson
- Revision 3: published
0 comments