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'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 
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'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".
And as you can see, it's running thousands of these operations in a single second. Unless you really need to squeeze out as many ops/second as possible, it doesn't matter which choice you pick. And when you get to that point, why choose JavaScript in the first place?
In closing, measure performance, but don't sweat it until after you're done adding functionality.

Make it work.
Make it right.
Make it fast.
You can follow @ralex1993.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: