jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
function f() {
return this;
}
var that = {
f: f
};
var bound = f.bind(that);
var that2 = Object.create(that);
var that3 = {};
var that4 = Object.create(that3);
function bind( fn, scope ){
var args = ( arguments.length > 2 ) ? [].slice.call( arguments, 2 ) : []
;
return function(){
var argList = arguments.length ? args.slice() : args;
for( var i=0, l=arguments.length; i<l; i++ ){
argList.push( arguments[i] );
}
var numArgs = argList.length;
return (
( numArgs < 10 )
? scope
? (
( 0 === numArgs ) ? fn.call( scope )
: ( 1 === numArgs ) ? fn.call( scope, argList[0] )
: ( 2 === numArgs ) ? fn.call( scope, argList[0], argList[1] )
: ( 3 === numArgs ) ? fn.call( scope, argList[0], argList[1], argList[2] )
: ( 4 === numArgs ) ? fn.call( scope, argList[0], argList[1], argList[2], argList[3] )
: ( 5 === numArgs ) ? fn.call( scope, argList[0], argList[1], argList[2], argList[3], argList[4] )
: ( 6 === numArgs ) ? fn.call( scope, argList[0], argList[1], argList[2], argList[3], argList[4], argList[5] )
: ( 7 === numArgs ) ? fn.call( scope, argList[0], argList[1], argList[2], argList[3], argList[4], argList[5], argList[6] )
: ( 8 === numArgs ) ? fn.call( scope, argList[0], argList[1], argList[2], argList[3], argList[4], argList[5], argList[6], argList[7] )
: ( 9 === numArgs ) ? fn.call( scope, argList[0], argList[1], argList[2], argList[3], argList[4], argList[5], argList[6], argList[7], argList[8] )
: '' // can't get here
)
: (
( 0 === numArgs ) ? fn()
: ( 1 === numArgs ) ? fn( argList[0] )
: ( 2 === numArgs ) ? fn( argList[0], argList[1] )
: ( 3 === numArgs ) ? fn( argList[0], argList[1], argList[2] )
: ( 4 === numArgs ) ? fn( argList[0], argList[1], argList[2], argList[3] )
: ( 5 === numArgs ) ? fn( argList[0], argList[1], argList[2], argList[3], argList[4] )
: ( 6 === numArgs ) ? fn( argList[0], argList[1], argList[2], argList[3], argList[4], argList[5] )
: ( 7 === numArgs ) ? fn( argList[0], argList[1], argList[2], argList[3], argList[4], argList[5], argList[6] )
: ( 8 === numArgs ) ? fn( argList[0], argList[1], argList[2], argList[3], argList[4], argList[5], argList[6], argList[7] )
: ( 9 === numArgs ) ? fn( argList[0], argList[1], argList[2], argList[3], argList[4], argList[5], argList[6], argList[7], argList[8] )
: '' // can't get here
)
: fn.apply( scope, argList )
);
}
}
var bound2 = bind( f, that );
var bound3 = bind( f );
Ready to run.
Test | Ops/sec | |
---|---|---|
direct |
| ready |
apply |
| ready |
call |
| ready |
bind |
| ready |
prototype |
| ready |
direct (dynamic property) |
| ready |
prototype (dynamic property) |
| ready |
fast bind |
| ready |
bind, no scope |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.