I too tried the Deparser first, but found that it wasn't changing the code on my machine:
C:\>perl -MO=Deparse -we "$a = 'doit'; print \"hi\n\" if $a eq 'doit'" $a = 'doit'; print "hi\n" if $a eq 'doit'; -e syntax OK C:\>perl -MO=Deparse -we "$a = 'doit'; if ($a eq 'doit'){print \"hi\n\ +"}" $a = 'doit'; if ($a eq 'doit') { print "hi\n"; } -e syntax OK
Then I tried the ol' benchmark and found that the two are more or less equivelent, which is what I expected. If anything the reverse method is slightly faster.
#!perl -w use strict; use Benchmark; sub Time { use vars qw( $clause ); $clause = shift; timethese( -5, { normal => sub { my $i = 0; if( $clause ) { ++$i } }, reverse => sub { my $i = 0; ++$i if $clause }, } ); } Time(1); Time(0); __END__ Output: Benchmark: running normal, reverse, each for at least 5 CPU seconds... normal: 6 wallclock secs ( 5.00 usr + 0.00 sys = 5.00 CPU) @ 97 +5640.40/s (n=4878202) reverse: 5 wallclock secs ( 5.21 usr + 0.00 sys = 5.21 CPU) @ 10 +03193.28/s (n=5226637) Benchmark: running normal, reverse, each for at least 5 CPU seconds... normal: 5 wallclock secs ( 5.27 usr + 0.00 sys = 5.27 CPU) @ 15 +65443.64/s (n=8249888) reverse: 4 wallclock secs ( 5.11 usr + 0.00 sys = 5.11 CPU) @ 15 +85628.38/s (n=8102561)

In reply to Re: Loops and speed by Adam
in thread Loops and speed by damian1301

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.