3 ms·
Since you are already doing it sequentially, why not do it in a loop? Something like: for(int i = 2; i <= 512; i *= 2) { if(x < i) { f(
by cmdli 11y ago
Since you are already doing it sequentially, why not do it in a loop? Something like:
for(int i = 2; i <= 512; i *= 2) {
if(x < i) {
f(x);
break;
}
}
It could be the same performance with some loop unrolling also; I don't know how much gcc does that.
- ginko 11y agoYou can also put the x < i part in the loop's head and check in advance that x < 512. That way you can get rid of the inner if.