instanceof vs typeof

Benchmark created on


Setup

const value = {
  1: () => {},
  2: {},
  3: 3,
  4: 'a',
  5: undefined,
  6: null,
}

Test runner

Ready to run.

Testing in
TestOps/sec
instanceof
let i = 0
for (const key in value) {
  if (value[key] instanceof Function) i++
}
ready
typeof
let i = 0
for (const key in value) {
  if (typeof value[key] === 'function') i++
}
ready

Revisions

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