3 ms·
It's too easy to wrongly believe you have a good Type 2 optimization. One might be tempted to replace their language's brute-force string searching with Boyer-M
by jakevoytko 16y ago
It's too easy to wrongly believe you have a good Type 2 optimization. One might be tempted to replace their language's brute-force string searching with Boyer-Moore... after all, it obviously uses fewer comparisons. But brute force is usually fast enough in regular text for non-search intensive applications - it can find the last sentence of Moby Dick in 5ms on my laptop. And most of us aren't searching through Moby Dick each time a webpage is loaded. I hope.
Optimizations should really only be made at the Type 1 level. I'm all for cleaning up and refactoring code. Your Type 2 example is really a Type 1 problem in disguise, since it's not the simplest way to do it! If you want to do a Type 2 change, measure it and prove to yourself it's worthy of your time. Just solve the problem simply and cleanly and hope for the best. The huge performance hogs are almost never where you expect to see them anyways.