in vs typeof (v3)

Revision 3 of this benchmark created by Nikita Vasilyev on


Description

Since elem.functionName calls the function in IE, check which is faster. 'functionName' in elem or typeof 'functionName' === 'function'

Preparation HTML

<div></div>
<script>
  function isUndefined(x) {
    return (typeof x !== 'undefined');
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
in
'getElementsByClassName' in document
ready
typeof
typeof document.getElementsByClassName === 'function'
ready
property
document.getElementsByClassName
ready
typeof undefined
typeof document.getElementsByClassName !== 'undefined'
ready
isUndefined()
isUndefined(document.getElementsByClassName)
ready
hasOwnProperty
document.hasOwnProperty('getElementsByClassName')
ready

Revisions

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

  • Revision 1: published by Timmy Willison on
  • Revision 2: published on
  • Revision 3: published by Nikita Vasilyev on