Array.prototype.includes

Benchmark created on


Description

Benchmark for Array.prototype.includes

Setup

const length = 1000000
const haystack = Array.from({ length }, (v, i) => i)
const needle = length - 1

Test runner

Ready to run.

Testing in
TestOps/sec
Array.prototype.includes
const found = haystack.includes(needle);
if (!found) throw new Error('Did not find needle');
ready
Native for-loop
let found = -1;
for (let i = 0; i < haystack.length; i++) {
	if (needle === haystack[i]) {
		found = i;
	}
}
if (found < 0) throw new Error('Did not find needle');
ready

Revisions

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