With 100 lines of comments to 2 lines of code, versus 100 blank lines to 2 lines of code, the commented code
takes 4.3 e-5 seconds longer to load & compile. Do away with the blank lines and it takes 10e-5 seconds longer.
So, even at this ludicrously high comment to code ratio, the time taken to process the comments is maybe 6/100,000 ths of a second.
And that happens just once per run of the code.
The differences shown in the runtime of the code are so small that they are influenced by whether you move the mouse during the test or not--and in my tests usually favoured the commented code! Atmospheric temperature changing the resistance of the cpu probably has more influence on the performance than the presence of absence of comments in the code. This is where benchmarking becomes totally inadequate.
Even the 16% difference below represents a real-time difference of 1.0e-7 of a second. That's one whole tenth of a microsecond.
#! perl -slw
use strict;
use Benchmark qw[ cmpthese ];
open O, '>', 'with.pl';
print O '# a comment', ' ' x 60, for 1 .. 100;
print O 'sub with{ $_[ 0 ]++; }';
print O 'our $with++';
close O;
open O, '>', 'without.pl';
print O ' ' x 80, for 1 .. 100;
print O 'sub without{ $_[ 0 ]++; }';
print O 'our $without++';
close O;
our( $with, $without );
{
local $^W;
( $with, $without ) = ( 0 ) x 2;
cmpthese -1, {
compile_with => q[ do 'with.pl'; ],
compile_without => q[ do 'without.pl'; ]
};
print "With:$with without:$without\n";
}
{
( $with, $without ) = ( 0 ) x 2;
cmpthese -1, {
A_call_with => q[ with( $with ); ],
B_call_without => q[ without( $without ); ]
};
print "With:$with without:$without\n";
}
{
( $with, $without ) = ( 0 ) x 2;
cmpthese -1, {
B_call_with => q[ with( $with ); ],
A_call_without => q[ without( $without ); ]
};
print "With:$with without:$without\n";
}
__END__
C:\test>junk
Rate compile_without compile_with
compile_without 3046/s -- -13%
compile_with 3507/s 15% --
With:4863 without:4447
Rate B_call_without A_call_with
B_call_without 1541400/s -- -4%
A_call_with 1602739/s 4% --
With:2476423 without:2258362
Rate A_call_without B_call_with
A_call_without 1552179/s -- -5%
B_call_with 1632288/s 5% --
With:2386728 without:2124584
C:\test>junk
Rate compile_without compile_with
compile_without 3001/s -- -11%
compile_with 3368/s 12% --
With:4863 without:4447
Rate B_call_without A_call_with
B_call_without 1405856/s -- -14%
A_call_with 1630859/s 16% --
With:2386728 without:1996218
Rate A_call_without B_call_with
A_call_without 1480385/s -- -11%
B_call_with 1655503/s 12% --
With:2386728 without:2142348
C:\test>junk
Rate compile_without compile_with
compile_without 3023/s -- -10%
compile_with 3365/s 11% --
With:4863 without:4469
Rate B_call_without A_call_with
B_call_without 1671100/s -- -0%
A_call_with 1676092/s 0% --
With:2277479 without:2250533
Rate A_call_without B_call_with
A_call_without 1575095/s -- -4%
B_call_with 1636763/s 4% --
With:2288717 without:2124584
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.