apply vs call vs invoke
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var obj = {
fn: function(a,b) {return a + b; }
};
var fn = obj.fn,
fnJsBound = jsBind(obj, fn),
fnBound = function() {};
if (fn.bind) {
fnBound = fn.bind(obj);
}
function jsBind(self, fn) {
return function() {
return fn.apply(self, arguments);
};
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
bind (native) (run if Function.prototype.bind exists) |
|
pending… |
bind (js) |
|
pending… |
direct invoke |
|
pending… |
direct invoke on obj |
|
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 Igor Minar
- Revision 2: published by Igor Minar
- Revision 3: published by Igor Minar
- Revision 4: published by Igor Minar
- Revision 5: published
- Revision 6: published by Igor Minar
- Revision 7: published by JulienW
- Revision 8: published by JulienW
- Revision 9: published
0 comments