Includes vs contains

Benchmark created on


Setup

const a = [5, 10, 15, 28, 39, 46, 49, 57, 66, 70, 75, 90, 100, 106, 107, 112, 123, 125, 129, 137, 150, 152, 176, 195, 203, 225, 235, 254, 264, 266, 292, 293, 305, 309, 324, 365, 367, 378, 382, 388, 402, 432, 472, 476, 480, 482, 488, 490, 497, 509, 523, 544, 563, 572, 573, 574, 575, 595, 613, 622, 624, 626, 628, 662, 665, 674, 686, 701, 704, 710, 715, 727, 730, 734, 741, 752, 767, 777, 781, 788, 792, 797, 800, 823, 824, 836, 841, 865, 882, 885, 890, 898, 920, 925, 928, 932, 940, 944, 955, 997];

const a_set = new Set(a);

Test runner

Ready to run.

Testing in
TestOps/sec
Array doesn't
a.includes(20);

ready
Array early
a.includes(5);
ready
Array late
a.includes(997);
ready
Set doesn't
a_set.has(20);
ready
Set early
a_set.has(5);
ready
Set late
a_set.has(997);
ready

Revisions

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