3 ms·
> Measure the performance of the target code in a specific situation A difficult part of optimization is actually trying to make the code work well in multiple
by kccqzy 1y ago
> Measure the performance of the target code in a specific situation
A difficult part of optimization is actually trying to make the code work well in multiple specific situations. This often happens in library code where different users call your code with very different sizes of inputs. Sometimes a dumb algorithm works better. Sometimes a fancier algorithm with better big-O but bigger constant factors works better. In practice people try to measure them according to the input size and dynamically choose the algorithm based on the size. This has the pitfall of the heuristic not keeping up with hardware. It also becomes intractable if the performance characteristics depend on multiple factors, then it's trying to encode the minimum in a multi-dimensional space. This work involved in optimization is just exhausting.
- addaon 1y agoThe other approach here is to provide access to the multiple implementations, documentation as to the (main) sensitivities for their performance, and let the caller do their own benchmarking to select the right one, based on the specific situations they care about. It's a bit of kicking the can down the road, but it's also a bit of allowing your customers (at least the ones who care) to get the best results possible.