Why is it faster to process a sorted array than an unsorted array? (2012)
stackoverflow.com
stackoverflow.com
But things are so complicated nowadays that's doesn't even come close to capturing the performance.
Is this the only way we can get good performance? Is there an alternative paradigm of optimization in hardware or software that would make performance tradeoffs more explicit? I don't know, but the current state of things makes me uneasy because I feel I never understand what's truly going on (and I definitely don't).
Throw in changing clock rates based on the temperature of the CPU. If your code efficiently uses the ALUs / cores in the processor, it can get hot and slow itself down.
So, that's the best general wisdom I know. Don't even bother trying to guess where you'll have performance problems. Profile it.
I've seen very unexpected results doing this. In one case, I put the inner loop in a separate function to enable swapping implementations and make it simpler to time. Surprisingly, the overall program ran faster without any other changes. Just pulling the inner loop into a function of its own sped things up.
My best guess was that the compiler was willing to put more effort into optimization on the smaller function. This contradicts common wisdom about function call overhead, and it also shows another level of complexity in the problem: Some compiler optimizations are exponential in their cost, so they punt if you put too much of your code in one block or function.
Also note that I wasn't able to prove this is what happened. It's just my best guess based on what I was able to see and infer.
The non-encrypted transport case had a similar change but there was no measurable performance difference before and after.
I'd like to know what perf stats are available to show what's going on. (I guess it's an L2 cache effect)
Basically, just think of this as repointing your registers to a register that's always zero. Note this only appears for the value zero.
This is one of the reasons you're supposed to wipe out sensitive data with random numbers, not zeros.
Also note that your compiler may copy data to the stack whenever it wants to. So even wiping out data with random numbers may not wipe out the copied data that lives (momentarily) on the stack.
https://webcourse.cs.technion.ac.il/234267/Winter2015-2016/h...
If you are in SO for the points, splitting them between two accounts seems lame. Remember that the question also collects points and badges!
I've never checked the user that answers to see if it's the same user that is asking, and it happened to me a couple of times that I tried to upvote my own answer.