logo       

Re: [SPOILER] Solution to Perl 'Expert' Quiz-of-the-Week #22: msg#00126

Subject: Re: [SPOILER] Solution to Perl 'Expert' Quiz-of-the-Week #22
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




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
linux.arklinux....    user-groups.lin...    kde.usability/2...    ietf.ipp/2002-0...    mail.spam.spamc...    os.netbsd.devel...    audio.cd-record...    text.unicode.de...    php.documentati...    games.fps.halfl...    window-managers...    suse.oracle.gen...    bug-tracking.gn...    video.dvdrip.us...    xfree86.cvs/200...    java.netbeans.m...    network.argus/2...    culture.sf.kill...    debian.ports.al...    freebsd.questio...    qplus.devel/200...    handhelds.palm....   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe