4 ms·
> Rules of thumb > Processors can 'learn' thousands of branches: benchmark over massive inputs. > Pick a solution without branches when it provides the same p
by Tuna-Fish 1y ago
> Rules of thumb
> Processors can 'learn' thousands of branches: benchmark over massive inputs.
> Pick a solution without branches when it provides the same performance.
Note that it is terrible idea to benchmark small parts of your software individually and compose together the parts that are individually the fastest. Branch history tables and branch target buffers are a shared resource, and performance can crater horribly if you routinely exceed what's provided. You should generally favor straight-line code even when it's slightly slower in microbenchmarks.
- dgacmu 1y agoIt's interesting how this happens with a lot of shared CPU resources, particularly cache, and even more particularly, icache: It's really easy when studying a small isolated component to end up at a solution that either uses more total instructions, or things like large lookup tables that end up composing badly in a more complicated context.
- deleted 1y ago[deleted]
- ahartmetz 1y ago> Note that it is terrible idea to benchmark small parts of your software individually and compose together the parts that are individually the fastest Certainly beats composing together the parts that are individually the slowest or not profiling at all. When you have to start worrying about shared CPU resources (main memory is a different matter), you are already doing much better than most software.