Why micro-performance and benchmarking is a farce: Which of these methods of checking whether a value exists in an array is the fastest?
Once you& #39;ve voted in the poll, take look at this benchmark. Be sure to check in in all three browser engines - Chrome, Firefox, and Safari. https://jsben.ch/ZiVWe ">https://jsben.ch/ZiVWe&quo...
I first ran it in Chrome, where `.includes` wins. "Oh, cool," I thought, "They must be optimizing for that path." But I was curious to know if it was consistent across JavaScript engines.
I tried Safari next, where the results were much closer, but `.indexOf` was clearly faster than the other ones. We are now 0/2 in terms of consistency. Which side will Firefox take?
Alas, it takes neither and charts its own course, the result I expected when I wrote the benchmark in the first place. Using a `for` loop to find the item is fastest.
Of course, this is a silly micro-benchmark that doesn& #39;t really test real-world situations, nor does it cover every case such as small arrays, large arrays, arrays of strings, etc. etc. This is more just for fun than real "serious research".