4 ms·
Depending on how you structure your loops, things can be optimized on how it hits the cache and reads contiguous memory addresses.
by warrenmar 10y ago
Depending on how you structure your loops, things can be optimized on how it hits the cache and reads contiguous memory addresses.
- theoh 10y agoThere was a time (late 90s) when GCC would optimize conditionals in an asymmetric way. Somebody will hopefully correct me, but I think the advice was to make conditionals usually be true, for best performance. Since most coders would never hear about this asymmetry (though that's just my impression) it was a bizarre case of favoring one branch of a conditional over another for purely historical (machine code) reasons.
- xentronium 10y agoI think some optimizations are still possible based on likeliness of conditionals. http://stackoverflow.com/questions/109710/likely-unlikely-macros-in-the-linux-kernel-how-do-they-work-whats-their http://stackoverflow.com/questions/109710/likely-unlikely-ma...
- striking 10y agoI think now branch prediction on processors can go either way, just as long as it's biased one way or another. If it's not biased one way or another, try to reduce out branches into vectorizable instructions (or pray that GCC takes care of it for you). Branch prediction isn't a GCC thing, it's a processor thing. Observe this wonderful Stack Overflow question: http://stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-an-unsorted-array http://stackoverflow.com/questions/11227809/why-is-processin...