Trying to figure out what will be optimal for a particular processor family is a job for the compiler/optimizer.
Super Geniuses that try to optimize this stuff themselves are just annoying to the people that have to maintain the code.
That's not to say there aren't some very specific circumstances where hand-optimization like this can make a big improvement on a problem that's actually limited by loop efficiency in a way that optimizers can't figure out, but normally it's a bad thing to think about.
Trying to figure out what will be optimal for a particular processor family is a job for the compiler/optimizer.
Which are not perfect. We can help them by writing code that is easy to optimise.
Super Geniuses that try to optimize this stuff themselves are just annoying to the people that have to maintain the code.
The example is changing an if to a conditional expression. It's not exactly complicated.
In general, if you take the "premature optimisation is evil" route, your architecture may be hamstrung from the very beginning. There's not a whole lot you can do if your code is a pointer soup of virtual functions and pointer-based data structures.
-1
u/hacksoncode 22h ago
Trying to figure out what will be optimal for a particular processor family is a job for the compiler/optimizer.
Super Geniuses that try to optimize this stuff themselves are just annoying to the people that have to maintain the code.
That's not to say there aren't some very specific circumstances where hand-optimization like this can make a big improvement on a problem that's actually limited by loop efficiency in a way that optimizers can't figure out, but normally it's a bad thing to think about.