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.
View all comments
Show parent comment
10
u/nukethebees Sep 03 '26
Which are not perfect. We can help them by writing code that is easy to optimise.
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.