Artificial vs. Native Bind
JavaScript performance comparison
Info
Determine performance gains of native bind. Note: artificial bind doesn't support partial application.
Preparation code
<script>
function artificial_bind(fn, context) {
return function() {
return fn.apply(context);
}
}
var bind;
if(Function.prototype.bind){
bind = function(fn, context){
var prependArgs = Array.prototype.slice.call(arguments, 2);
return fn.bind(context, prependArgs);
};
}
function test(arg) {
var i;
for (i = 0; i < 1000; i++) {
arg += i;
}
this.lol = arg;
}
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Artificial |
|
pending… |
Native |
|
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 gf3
- Revision 3: published
- Revision 4: published
- Revision 5: published
0 comments