Equality Comparisons (v9)

Revision 9 of this benchmark created on


Setup

const numbers = [];
const numbersNan = [];
const booleans = [];
const strings = [];
const objs = [];
const objsMega = [];
const coercion = [];
const coercionMega = [];
const mix = [];
const mixSelector = [numbers, booleans, strings, objs]

for(let i=0; i<1000; i++) {
	numbers.push(i);
	numbersNan.push(i%2 ? Number.NaN: 1);
	booleans.push(i%2 == 0);
	strings.push('' + i);
	coercion.push({valueOf: () => "" + i});
	objs.push({});
	objsMega.push({
		['_' + i]: i
	});
	coercionMega.push({
		['_' + i]: i,
		valueOf: () => "" + i
	});
	const array = mixSelector[i%mixSelector.length];
	mix.push(array[i]);
}

Test runner

Ready to run.

Testing in
TestOps/sec
numbers ==
let sum = false;
for (i = 0; i< numbers.length; i++) {
	sum = numbers[i] == -1 || sum;
}
ready
numbers ===
let sum = false;
for (i = 0; i< numbers.length; i++) {
	sum = numbers[i] === -1 || sum;
}
ready
strings ==
let sum = false;
for (i = 0; i< strings.length; i++) {
	sum = strings[i] == -1 || sum;
}
ready
strings ===
let sum = false;
for (i = 0; i< strings.length; i++) {
	sum = strings[i] === -1 || sum;
}
ready
mix ==
let sum = false;
for (i = 0; i< mix.length; i++) {
	sum = mix[i] == -1 || sum;
}
ready
mix ===
let sum = false;
for (i = 0; i< mix.length; i++) {
	sum = mix[i] === -1 || sum;
}
ready
coercion ==
let sum = false;
for (i = 0; i< coercion.length; i++) {
	sum = coercion[i] == -1 || sum;
}
ready
coercion ===
let sum = false;
for (i = 0; i< coercion.length; i++) {
	sum = coercion[i] === -1 || sum;
}
ready
coercion Object.is
let sum = false;
for (i = 0; i< coercion.length; i++) {
	sum = Object.is(coercion[i], -1) || sum;
}
ready
objs ==
let sum = false;
for (i = 0; i< objs.length; i++) {
	sum = objs[i] == -1 || sum;
}
ready
objs ===
let sum = false;
for (i = 0; i< objs.length; i++) {
	sum = objs[i] === -1 || sum;
}
ready
objsMega ==
let sum = false;
for (i = 0; i< objsMega.length; i++) {
	sum = objsMega[i] == -1 || sum;
}
ready
coercionMega ==
let sum = false;
for (i = 0; i< coercionMega.length; i++) {
	sum = coercionMega[i] == -1 || sum;
}
ready
numbersNan ==
let sum = false;
for (i = 0; i< numbersNan.length; i++) {
	sum = numbersNan[i] == -1 || sum;
}
ready
numbersNan ===
let sum = false;
for (i = 0; i< numbersNan.length; i++) {
	sum = numbersNan[i] === -1 || sum;
}
ready

Revisions

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