JSベンチ実測MEASURED, NOT RECALLED

    ↑↓ で選択、Enter で開く。Esc で閉じる。

    Home / Findings

    `Array.includes` is ~28× slower than `Set.has`

    If you test membership repeatedly, convert the array to a Set. Over 200,000 lookups the gap reaches 28×.

    Result

    Run`Array.includes` (100k array)`Set.has` (same contents)Ratio
    Run 1462.04015.70029.43×
    Run 2446.24214.83330.08×
    Run 3460.71417.79725.89×

    Median spread: `Array.includes` (100k array) CV 1.6% / `Set.has` (same contents) CV 7.7% / Ratio CV 6.5% (computed from the 3 runs)

    Conditions

    200,000 membership tests against a 1,000-item set.

    Where this number does not apply

    For a few dozen lookups, building the Set costs more than it saves. Keep the array for one-off checks.

    Reproduce

    cd bench
    node --expose-gc micro-fixed.mjs --out ../data/run.json --samples 21

    Run it three times on the same machine; if the spread of median stays under 10%, you should land on the same conclusion. If your numbers disagree, tell us and we will retract.