Unfortunately, I think there is at least *one* corner case where having comments actually do make a difference: extended regular expressions with interpolated variables with or without comments.

Mind you, you're going to have to do a lot of regular expressions before you actually start noticing this.

use Benchmark qw(:hireswallclock cmpthese); my $bappo = 'bappo'; my $foo = "foo bar baz bippo $bappo zappo"; cmpthese( -3, { extended => sub { $foo =~ / $bappo \s+ (zappo) /x; }, comment => sub { $foo =~ / $bappo # this is a comment \s+ # inside an extended (zappo) # regular expression /x; }, no_comment => sub { $foo =~ /$bappo\s+(zappo)/ }, } ); __END__ Rate comment extended no_comment comment 480920/s -- -11% -22% extended 542294/s 13% -- -12% no_comment 614847/s 28% 13% --

The reason for this is most likely because of the variable interpolation (so Perl cannot store a compiled version of the regular expression) and the fact that extended comments are actually part of the string when the regular expression is being compiled.

Of course, most regular expressions that warrant the extended format with comments, are also the more complicated ones, so in the real world, this might still be a bit worse. (I leave this as an excercise for the reader).

On the other hand, saving one hour of your coworkers time when (s)he has to look at your code, is usually worth much more, so your mileage may vary ;-)

Liz


In reply to Re^2: Are there any drawbacks to comments -- can they hurt the performance of Perl code? by liz
in thread Are there any drawbacks to comments -- can they hurt the performance of Perl code? by jira0004

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.