Skip to content

Instantly share code, notes, and snippets.

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 ifraixedes/850dd705daea4f39ed31 to your computer and use it in GitHub Desktop.
Save ifraixedes/850dd705daea4f39ed31 to your computer and use it in GitHub Desktop.
Function bind execution time with and without prepending a argurment
var title = "Sir,";
var obj = {
name: 'Ivan'
};
function getName(title) {
return title + " " + this.name;
}
// Iteration binded function without prepending any argument
fun = getName.bind(obj);
initTime = Date.now();
for (i = 0; i < NUM_ITERATIONS; i++) {
fun(title);
}
stopTime = Date.now();
console.log('Iterate using binded function without prepending any argument: %s ms', stopTime);
// Iteration binded function prepending a argument
fun = getName.bind(obj, title);
initTime = Date.now();
for (i = 0; i < NUM_ITERATIONS; i++) {
fun()
}
stopTime = Date.now();
console.log('Iterate using binded function prepending a argument: %s ms', stopTime);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment