Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Array.includes() vs Set.has() for small Arrays invoked multiple times
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser:
Chrome 133
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Array.includes, 20 elements
25024786.0 Ops/sec
Set.has, 20 elements
47552832.0 Ops/sec
Array to Set + Set.has x 1000, 20 elements
45698.8 Ops/sec
Array.includes x 1000, 20 elements
26838.8 Ops/sec
Script Preparation code:
function getArray(length) { const result = []; for (let i = 0; i < length; i++) { result.push(i + 'abc'); // In case the browser does some sort of optimization for arrays with only integers ¯\_(ツ)_/¯ } return result; } function getRandomTargetElement(arrayLength) { const index = Math.floor(Math.random() * arrayLength); return index + 'abc'; } array_small = getArray(20); set_small = new Set(array_small);
Tests:
Array.includes, 20 elements
array_small.includes(getRandomTargetElement(20));
Set.has, 20 elements
set_small.has(getRandomTargetElement(20))
Array to Set + Set.has x 1000, 20 elements
const set = new Set(array_small); for (let i = 0; i < 1000; i++) { const target = getRandomTargetElement(20); set.has(target) }
Array.includes x 1000, 20 elements
for (let i = 0; i < 1000; i++) { const target = getRandomTargetElement(20); array_small.includes(target) }