On Sun, Aug 29, 2004 at 10:27:18AM +0200 Xavier Noria wrote:
> On Aug 29, 2004, at 9:18, Tassilo von Parseval wrote:
> >>__DATA__
> >>__C__
> >>#include <string.h>
> >>
> >>/* Returns the number of substitutions needed to go from word1 to
> >>word2.
> >> Assumes word1 and word2 have the same length. */
> >>int distance(char* word1, char* word2)
> >>{
> >> int subs = 0;
> >> for (int i = 0; i < strlen(word1); ++i)
> >
> >Since words are usually short, this is not a big deal. Nonetheless,
> >C-for evaluates its second argument on each iteration. Therefore, the
> >strlen() is calculated each time.
>
> I left it there on purpose because I think I saw in comp.lang.c years
> ago that a good compiler would optimize that call. There was a
> guideline in some responses of regulars ("was" meaning when I monitored
> the group) that said that the programmer wouldn't need to worry about
> those details unless he knows what he is doing. The reason was the
> compiler, they said, will normally be more smart than the programmer.
Yes, this seems to be the case (with my compiler, anyway). After sending
my comments, I modified your C code accordingly and if there was any
effect at all, it got slower instead of faster. :-)
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
|