4 ms·
> Well, seems like it does matter. Using an array is 50% slower than using an object and that's slower than using a Set in Chrome. A 50% difference doesn't mea
by thomasahle 6y ago
> Well, seems like it does matter. Using an array is 50% slower than using an object and that's slower than using a Set in Chrome.
A 50% difference doesn't mean it matter. Unless this runs in some inner loop, just use the simplest solution.
- gfxgirl 6y agoI agree that if the fast solution is 10x the code then maybe choose another solution. In this case all 6 solutions are basically the same amount of code. There's absolutely no reason to choose the slowest solution. 50% can easily be the difference between some VSCode extension making it sluggish vs not. Further, in my experience slow solutions will eventually come back to bite you. One I saw recenty. see if 2 arrays contain the same elements. The "simple" solution is sort copies of the arrays, concat them into strings, compare the strings. It looks simple but it's around 1000x slower than pretty much any normal but not 1 line solution. 1000x won't matter when you're testing your 5 element arrays in your unit test but it will matter then your users start using larger arrays.
- thomasahle 6y agoAt least in the blog post, the alternative solution has 10x the number of lines. Of course, if you benchmark and this turns out to be important, try to optimize it.