Every isNaN

JavaScript performance comparison

Revision 9 of this test case created

Info

This test is meant to consolidate several isNaN techniques. Please update with any isNaN alternatives you know, and test on every possible JavaScript agent.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    x = "str";
    y = 43;
    z = NaN;
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
isNaN function
if(isNaN(x));
if(isNaN(y));
pending…
"" + NaN
if(x+"" === "NaN");
if(y+"" === "NaN");
pending…
+NaN
if(+x !== NaN);
if(+y !== NaN);
pending…
<= && >
if (!(x <= 0) && !(x > 0));
if (!(y <= 0) && !(y > 0));
pending…
<= || >
if (x <= 0 || x > 0);
if (y <= 0 || y > 0);
pending…
typeof
if (typeof x === 'number');
if (typeof y === 'number');
 
pending…
~~a === a
if (~~x === x);
if (~~y === y);
pending…
equality
if( x !== x);
if( y !== y);
pending…
!isNaN
isNaN(z);
pending…
bitwise or
z | 0;
pending…
logical or
z || 0;
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment