typeof function check vs. noop function

Benchmark created on


Description

We have a default value for a variable which could be a function. Is it faster to check if it is a function and don't call it if not or is it faster to call a noop function?

Setup

const maybeFunction = null
const noop = () => {}

Test runner

Ready to run.

Testing in
TestOps/sec
typeof function check
if (typeof maybeFunction === 'function') {
  maybeFunction()
}
ready
Calling the noop
noop()
ready

Revisions

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