3 ms·
I 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
by gfxgirl 6y ago
I 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.