Set vs Array.includes

Benchmark published by System on

Description

Compare checking existence in a Set vs an Array.

Setup

const size = 10000;
const arr = Array.from({length: size}, (_, i) => i);
const set = new Set(arr);
const target = size / 2;

Test Runner

Initializing...

Testing in
Test CaseOps/sec
Set.has
set.has(target);
ready
Array.includes
arr.includes(target);
ready
Array.indexOf
arr.indexOf(target) !== -1;
ready

Revisions

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

Revision 1
publishedby Systemon