well i'm building some javascript code and im just curious about benchmark of passing function in argument vs direct access
I got following functions
testIt(function(){
alert('Hi test');
});
function testIt(func){
func();
};
function testIt2(){
alert('Hi test');
};
And now how about testIt vs testIt2? Would testIt be slower?
I test it on jspref and here is my result:
Anonymous call have the same speed with direct call. But creating function on fly work ~80% slower.
So if you want to run some code in cycle — first define function and than pass it anonymously. It give enough readability and speed.