title: Performance: typeof vs instanceof
body: <p>I was wondering which one of <code>typeof</code> and <code>instanceof</code> is more performant, so I threw together the following little thing:</p>
  
  <pre class="lang-js prettyprint-override"><code>let TIMES = 1000 * 1000 * 100
  
  console.time("(() =&gt; { }) instanceof Function")
  for (let i = 0; i &lt; TIMES; i++)
    (() =&gt; { }) instanceof Function
  console.timeEnd("(() =&gt; { }) instanceof Function")
  
  console.time("(async () =&gt; { }) instanceof Function")
  for (let i = 0; i &lt; TIMES; i++)
    (async () =&gt; { }) instanceof Function
  console.timeEnd("(async () =&gt; { }) instanceof Function")
  
  console.time("(function () { }) instanceof Function")
  for (let i = 0; i &lt; TIMES; i++)
    (function () { }) instanceof Function
  console.timeEnd("(function () { }) instanceof Function")
  
  console.time("(async function () { }) instanceof Function")
  for (let i = 0; i &lt; TIMES; i++)
    (async function () { }) instanceof Function
  console.timeEnd("(async function () { }) instanceof Function")
  
  console.time("typeof (() =&gt; { }) === 'function'")
  for (let i = 0; i &lt; TIMES; i++)
    typeof (() =&gt; { }) === 'function'
  console.timeEnd("typeof (() =&gt; { }) === 'function'")
  
  console.time("typeof (async () =&gt; { }) === 'function'")
  for (let i = 0; i &lt; TIMES; i++)
    typeof (async () =&gt; { }) === 'function'
  console.timeEnd("typeof (async () =&gt; { }) === 'function'")
  
  console.time("typeof (function () { }) === 'function'")
  for (let i = 0; i &lt; TIMES; i++)
    typeof (function () { }) === 'function'
  console.timeEnd("typeof (function () { }) === 'function'")
  
  console.time("typeof (async function () { }) === 'function'")
  for (let i = 0; i &lt; TIMES; i++)
    typeof (async function () { }) === 'function'
  console.timeEnd("typeof (async function () { }) === 'function'")
  </code></pre>
  
  <p>And got these super cool results from Chrome 66's console:</p>
  
  <pre class="lang-none prettyprint-override"><code>(() =&gt; { }) instanceof Function: 1789.844970703125ms
  (async () =&gt; { }) instanceof Function: 2229.64208984375ms
  (function () { }) instanceof Function: 1954.09716796875ms
  (async function () { }) instanceof Function: 2279.995849609375ms
  typeof (() =&gt; { }) === 'function': 412.8701171875ms
  typeof (async () =&gt; { }) === 'function': 413.337890625ms
  typeof (function () { }) === 'function': 413.387939453125ms
  typeof (async function () { }) === 'function': 412.910888671875ms
  </code></pre>
  
  <p>Firefox 59 took forever to run that XD</p>
  
  <p>I didn't have enough patience to wait for it and made TIMES ten times less:</p>
  
  <pre class="lang-js prettyprint-override"><code>let TIMES = 1000 * 1000 * 10
  </code></pre>
  
  <p>With that I got the following out of Firefox 59's console:</p>
  
  <pre class="lang-none prettyprint-override"><code>(() =&gt; { }) instanceof Function: 5490ms
  (async () =&gt; { }) instanceof Function: 6884ms
  (function () { }) instanceof Function: 5408ms
  (async function () { }) instanceof Function: 6938ms
  typeof (() =&gt; { }) === 'function': 1916ms
  typeof (async () =&gt; { }) === 'function': 1998ms
  typeof (function () { }) === 'function': 1976ms
  typeof (async function () { }) === 'function': 1972ms
  </code></pre>
  
  <p>Both result sets show that <code>typeof</code> is much faster than <code>instanceof</code>, the fact a couple of other people also mentioned in <a href="https://stackoverflow.com/questions/899574/which-is-best-to-use-typeof-or-instanceof">Which is best to use: typeof or instanceof?</a>.</p>
  
  <p>My question is "y tho"?</p>