all same? (v2)

Revision 2 of this benchmark created on


Description

checking if all values in an array are the same

Setup

var values = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];
var firstVal = values[0];
var allSame = true;

Test runner

Ready to run.

Testing in
TestOps/sec
Set
let x = new Set(values);
allSame = x.size == 1;
ready
every
allSame = values.every(x => x == firstVal);
ready
loop
for (let i=0; i<values.length; i++) {
	if (values[i] !== firstVal) {
		allSame = false;
		break;	
	}
}
ready

Revisions

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