4 ms·
Rule of thumb #1: don't. The compiler is probably smarter than you, it can handle things itself most of the time. Rule of thumb #2: always test low-level perfo
by sellyme 5y ago
Rule of thumb #1: don't. The compiler is probably smarter than you, it can handle things itself most of the time.
Rule of thumb #2: always test low-level performance improvements on real data. This is very similar to rule #1 - the compiler might already be implementing the optimisation you're changing to, so you might be making the code less readable for no benefit.
Rule of thumb #3: sort your arrays. Sorting algorithms are one of the most aggressively-optimised functions in modern computer science, it's a very small overhead compared to regular branch prediction failures. Make sure to keep rules #1 and #2 in mind, but this is probably the most common significant performance improvement to be gleaned from branch prediction.
- fomine3 5y agoFamous SO for #3 https://stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-processing-an-unsorted-array https://stackoverflow.com/questions/11227809/why-is-processi...