generated function
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
function generic(func, length){
length = length || func.length;
if(!length) return function(context){
return func.call(context);
}
if(length < 0) return function(context){
return func.apply(context, Array.prototype.slice.call(arguments, 1));
}
var i = 0, args = ['c'], sargs;
for(; i < length; i++)
args[i + 1] = 'a' + i;
sargs = args.join(',');
return Function('f', 'return function(' + sargs + '){return f.call(' + sargs + ');}')(func);
}
var array = [1, 2, 3,1, 2, 3, 1, 2, 3, 1, 2, 3];
var manualSlice = (function(){
var nativeSlice = Array.prototype.slice;
return function(object, a, b){
return nativeSlice.call(object, a, b);
}
})();
var slice = generic(Array.prototype.slice);
var manualToString = (function(){
var nativeToString = Object.prototype.toString;
return function(object){
return nativeToString.call(object);
}
})();
var toString = generic(Object.prototype.toString);
var ops = Object.prototype.toString;
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
manual slice |
|
pending… |
generated slice |
|
pending… |
manual toString |
|
pending… |
generated toString |
|
pending… |
direct call toString |
|
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 carrilho and last updated
- Revision 2: published by carrilho
0 comments