Created
October 31, 2014 18:34
-
-
Save ifraixedes/850dd705daea4f39ed31 to your computer and use it in GitHub Desktop.
Function bind execution time with and without prepending a argurment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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