Re: break statement in a for loop



It's not my objective to show you the full code; it's about the issue
of execution speed and "break".


Richard Heathfield schreef:
a.mil@xxxxxxxxx said:

Ok, this was a bad fast example, I admit.
Therefore below another example that shows the point.


int main()
{
unsigned long i,j,k,l,n;

for (l=0;l<10000000;l++) {
j=0;
k=10;
n=231;

for (i=1;n>3;j+=8,k+=j,n-=2) {
if (k%n) continue;
i=0;
break;
}
}
return 0;
}


Run this without the break statement and with the break statement and
look at execution time. On my 1.5GHz P4 it takes 1.3s and 13.9s
respectively (!). My store on the factor 100 incorporates a lot more
code.

The same result can be achieved much more quickly:

int main(void)
{
return 0;
}

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.

.



Relevant Pages

  • Re: break statement in a for loop
    ... Run this without the break statement and with the break statement and ... int main ... Richard Heathfield ... rjh at the above domain, ...
    (comp.lang.c)
  • Re: Interesting code
    ... Richard Heathfield wrote: ... int sqrt ... function name choice invades implementation namespace, thus invoking ... value regardless, thus invoking undefined behaviour; ...
    (comp.lang.c)
  • Re: Pointers in C
    ... Richard Heathfield wrote: ... reasons. ... int main ... My compiler is determined ...
    (comp.lang.c)
  • Re: union
    ... Richard Heathfield wrote: ... sizeof yields a size_t, not an int, so %d is not an appropriate printf ... format specifier for it. ...
    (comp.lang.c)
  • Re: C newbie in a jam
    ... Richard Heathfield skrev: ... populate the array, and then write it to a file, read it again and the ... You are also not showing us the code you are actually compiling, ... double readfile(double *, int, int, double); ...
    (comp.lang.c)