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
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|