marioroy has asked for the wisdom of the Perl Monks concerning the following question:

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;


perl perl 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