Skip to content

Instantly share code, notes, and snippets.

@uhop
Created October 4, 2010 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uhop/609265 to your computer and use it in GitHub Desktop.
Save uhop/609265 to your computer and use it in GitHub Desktop.
Calling function
// Benchmarking different ways to call a function.
var context = {}, fb = null;
function test(){}
this.group(
"Calling function",
function Normal(x){ return test(x); },
{
name: "Function.call()",
test: function(x){ return test.call(context, x); }
},
{
name: "Function.apply()",
test: function(x){ return test.apply(context, arguments); }
},
{
name: "bind()",
setup: function(){ fb = bind(test, context); },
test: function(x){ fb(x); }
},
{
name: "Function.bind()",
setup: function(){ fb = test.bind(context); },
test: function(x){ fb(x); }
}
);
// utilities
function bind(f, o){
return function(){ return f.apply(o, arguments); };
}
@uhop
Copy link
Author

uhop commented Oct 4, 2010

Benchmark it with http://www.perfjs.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment