all same?

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;

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
allSame = true;
for (let i=0; i<values.length; i++) {
	if (values[i] !== firstValue) {
		allSame = false;
		break;	
	}
}
ready

Revisions

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