A
a.mil
I am programming for code-speed, not for ansi or other nice-guy stuff
and I encountered the following problem:
When I have a for loop like this:
b=b0;
for (a=0,i=0;i<100;i++,b--) {
if (b%i) continue;
a=1;
}
I want to break out of the loop -fast- after a==1. When I put a break
after it like in
b=b0;
for (a=0,i=0;i<100;i++,b--) {
if (b%i) continue;
a=1;
break;
}
the former fast loop turns into a horribly (factor 100 or so...) slow
one, so better to use no break at all in my opinion.
Does anyone know exactly -why- the break statement makes the loop so
slow??
Isn't it just an extra "jmp" in assembler equivalent code? I compared
both assembled outputs with and without the break statement, but they
really look quite different.. ?! I optimize with -O3 using gcc.
and I encountered the following problem:
When I have a for loop like this:
b=b0;
for (a=0,i=0;i<100;i++,b--) {
if (b%i) continue;
a=1;
}
I want to break out of the loop -fast- after a==1. When I put a break
after it like in
b=b0;
for (a=0,i=0;i<100;i++,b--) {
if (b%i) continue;
a=1;
break;
}
the former fast loop turns into a horribly (factor 100 or so...) slow
one, so better to use no break at all in my opinion.
Does anyone know exactly -why- the break statement makes the loop so
slow??
Isn't it just an extra "jmp" in assembler equivalent code? I compared
both assembled outputs with and without the break statement, but they
really look quite different.. ?! I optimize with -O3 using gcc.