Native bind versus wrapping when appending two arguments (v11)

Revision 11 of this benchmark created by Michael on


Preparation HTML

<script>
"use strict";
		
		var wrapFunction  = function( fn, context ) {
			return function() {
				var args = new Array( arguments.length + 2 );
				args[0] = "arg 1";
				args[1] = "arg 2";
				var n = 2;
				for ( var i = 0; i < arguments.length; n++, i++ )
					args[n] = arguments[i];
				return fn.apply( context, args );
			};
		};
		
		// Test object
		var obj = {
			prop: "prop",
			test: function( a, b, c ) {
var d = a + b + c + this.prop;
return d; // just to do something
			}
		};
		
		// Using custom method
		var wrapped = wrapFunction( obj.test, obj );
		// wrapped("a");
		
		// Using native bind
		var bound = obj.test.bind( obj, "arg 1", "arg 2" );
		// bound("a");

</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Calling wrapped
wrapped("a");
ready
Calling bound
bound("a");
ready
wrapping and calling
var wrapped = wrapFunction( obj.test, obj );
wrapped("a");
		
ready
binding and calling
var bound = obj.test.bind( obj, "arg 1", "arg 2" );
bound("a");
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.