isNaN vs isFinite vs !== (v5)

Revision 5 of this benchmark created by muffin on


Setup

numsamples = [2, 2.2, 'a', '2', '2 3', 0x00eef];
    index = Math.floor(Math.random()*numsamples.length);
    this.input = numsamples[index];
    
    if (!Number.isInteger) {
      // Polyfill from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
      Number.isInteger = function isInteger (nVal) {
        return typeof nVal === "number" && isFinite(nVal) && nVal > -9007199254740992 && nVal < 9007199254740992 && Math.floor(nVal) === nVal;
      };
    }

Test runner

Ready to run.

Testing in
TestOps/sec
isNaN
!isNaN(this.input)
ready
isFinite
isFinite(this.input)
ready
typeof Number
typeof (this.input) === 'number'
ready
isInteger
Number.isInteger(this.input)
ready
===
this.input === +this.input;
ready

Revisions

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