Check for function vs no-op (v3)

Revision 3 of this benchmark created on


Description

Compare checking a variable is a function before invoking it, versus assigning a default no-op function and always invoking it.

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Setup

var notAFunc,
    noOp = function(){};

Test runner

Ready to run.

Testing in
TestOps/sec
Check if present
if(notAFunc) {
notAFunc();
}
ready
Function check
if (typeof notAFunc === 'function') {
notAFunc();
}
ready
jQuery function check
if ($.isFunction(notAFunc)) {
notAFunc();
}
ready
Execute
noOp();
ready
Conditional Execution
(notAFunc || noOp)();
ready

Revisions

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