[26061] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 8267 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 21 21:05:28 2005

Date: Thu, 21 Jul 2005 18:05:03 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 21 Jul 2005     Volume: 10 Number: 8267

Today's topics:
    Re: Strange speed-increase by separating "if"s <No_4@dsl.pipex.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 21 Jul 2005 23:22:34 +0100
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: Strange speed-increase by separating "if"s
Message-Id: <KrSdneDW2u6xvX3fRVnyjQ@pipex.net>

Wolfram Humann wrote:
t...
> If my brain isn't totally drained already the correctly split version 
> should be:
> 
> if ($_ =~ /$c_dot[$d]/)
> {
>     if ($1 < $x - $r - 2 or
>         $1 > $x + $r + 2 or
>         $2 < $y - $r - 2 or
>         $2 > $y + $r + 2)
>     {
> 
> Naturally, with this the timing is more or less back to what it was. 
> According to profiling, the four comparisons take about as much time as 
> the pattern match -- hence the speed increase when they never executed :-)

    You are (probably) doing 4 calculations to work out constants.

    Might be quicker if you did:

  $x_less_r2 = $x - $r - 2;
  $x_plus_r2 = $x + $r + 2;
  $y_less_r2 = $y - $r - 2;
  $y_plus_r2 = $y + $r + 2;

(having declared them in a suitable scope) as soon as you get x and y then 
change your test to use the calculated version.  Of course, it depends on 
how many times the test is run for each head branch taken (and whether Perl 
  optimizes this anyway).


-- 
              Just because I've written it doesn't mean that
                   either you or I have to believe it.


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 8267
***************************************


home help back first fref pref prev next nref lref last post