3 ms·
This is of course an optimization which is hyper specific and in fact near useless in practice. Converting an awful algorithm into a superior form (from O(N) t
by constantcrying 3y ago
This is of course an optimization which is hyper specific and in fact near useless in practice.
Converting an awful algorithm into a superior form (from O(N) to O(1)) is a neat trick, but obviously can only apply if:
- Such an algorithm can be easily detected by the Compiler and there is actually a replacement algorithm which does exactly the same thing within the defined behavior. These cases are very rare.
- The programmer is unable or unwilling to identify the optimization, which in most cases means he does not understand his algorithm well or does not care about performance.
Just as an example this substitutions CAN NOT be applied if you replace ints with floats. Of course the O(1) algorithm is still generally preferable in that case a Compiler will never help you with that if you use floats.