Respected Monks,
On Mac OS X and Linux (not tested on other Unix platforms), there appears to be extra overhead by Perl prior to the script exiting for variables declared with my. The extra time is noticeable after seeing the "end" output.
Why does Perl have this odd behavior during cleanup?
use strict;
use warnings;
$| = 1;
my $size = 2e6;
my $data =
[ 'AGCTCGTTGTTCGATCCA', 'GAGAGATAGATGATAGTG', 'TTTT_CCCC', 0 ];
print "begin\n";
my %barcode_hash = map { $_ => $data } 1 .. $size;
print "end\n";
There is practically no delay after seeing "end" if I declare the variable with our.
...
our %barcode_hash = map { $_ => $data } 1 .. $size;
...
I made a script to capture the running time, helpful on Windows. Unix has time command and shell builtin time.
use strict;
use warnings;
use Time::HiRes 'time';
my $start_time = time;
system(@ARGV) == 0 or die "\"@ARGV\" failed with error: $?";
printf "%0.03f seconds\n", time - $start_time;
Results:
perl timeit.pl perl test.pl
my %big_hash: 2.726 seconds
our %big_hash: 1.351 seconds
Thank you, karlgoethebier for this enlightenment. I do not understand what Perl is doing during cleanup. Has anyone encountered this behavior? I tested on Windows and is nothing like seen on Mac OS X and Linux.
Thanks, Mario
-
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.