direct v call v apply
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var A;
A = (function() {
function f2(a, b, c) {
var _a = a.toString();
var _b = b.toString();
var _c = c.toString();
}
var f3 = function(a, b, c) {
var _a = a.toString();
var _b = b.toString();
var _c = c.toString();
}
function A() {}
A.prototype = {
fn: function(a, b, c) {
var _a = a.toString();
var _b = b.toString();
var _c = c.toString();
},
_direct: function(a, b, c) {
this.fn(a, b, c);
},
_cached_f2: function(a, b, c) {
f2(a, b, c);
},
_cached_f3: function(a, b, c) {
f3(a, b, c);
},
_call: function(a, b, c) {
f2.call(this, a, b, c);
},
_apply_array: function(arr) {
f2.apply(this, arr);
},
_apply_arguments: function(a, b, c) {
f2.apply(this, arguments);
}
};
return A;
})();
var a = 10,
b = "something",
c = [10, 20, 30];
var arr = [a, b, c];
var inst = new A();
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Direct |
|
pending… |
Call |
|
pending… |
Apply - array |
|
pending… |
Apply - arguments |
|
pending… |
Call cached 1 |
|
pending… |
Call cached 2 |
|
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 Byron
- Revision 2: published
- Revision 3: published
- Revision 4: published
- Revision 5: published
- Revision 6: published
0 comments