NaN comparisons

Benchmark created on


Setup

const a = new Float32Array(1e8);
a[0] = NaN;
const NAN_VALUE = new Float32Array([-12345.6789])[0];
a[1] = NAN_VALUE;

Test runner

Ready to run.

Testing in
TestOps/sec
isNaN
let numNans = 0;
for (let i = 0; i < a.length; i++) {
	if (isNaN(a[i])) numNans++;
}
ready
value !== value
let numNans = 0;
for (let i = 0; i < a.length; i++) {
	if (a[i] !== a[i]) numNans++;
}
ready
value !== NAN_VALUE
let numNans = 0;
for (let i = 0; i < a.length; i++) {
	if (a[i] === NAN_VALUE) numNans++;
}
ready

Revisions

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