Weel I thought that Rich36's benchmark was a little flawed, but the results turned out, not the way I thought.

The benchmark below uses his code(modified), and demonstrates that there is considerable overhead to using %ENV (I hope I did it right).

Check it out (readmore)

#!/usr/bin/perl -w use strict; use Benchmark; ## I eliminated the print statements used inside the benchmark ## they weren't really useful/neccessary ## the speed diff comes from the fact that %ENV really is %main::ENV ## and $foo is not in main ## I will show that now by adding a $foo in main ## also, %ENV is a hash, so I have made %foo and %FOO a hash ## in fact, I made them copies of %ENV ## that way we get into no funky business sleep 1; { # Start the benchmark $ENV{PATH}=1; my $start = new Benchmark; for(1..100000) { $ENV{PATH}++; } # End the program and return the Benchmark time my $end = new Benchmark; print "Processing time was...\n"; print timestr(timediff($end, $start)) . "\n"; print scalar(%ENV)."\n"; } sleep 1; { my %foo = map { $_ => $ENV{$_} } keys %ENV; $foo{PATH} = 1; # Start the benchmark my $start = new Benchmark; for(1..100000) { $foo{PATH}++; } # End the program and return the Benchmark time my $end = new Benchmark; print "Processing time was...\n"; print timestr(timediff($end, $start)) . "\n"; print scalar(%foo)."\n"; } sleep 1; { use vars qw / %FOO /; %FOO = map { $_ => $ENV{$_} } keys %ENV; $FOO{PATH} = 1; # Start the benchmark my $start = new Benchmark; for(1..100000) { $FOO{PATH}++; } # End the program and return the Benchmark time my $end = new Benchmark; print "Processing time was...\n"; print timestr(timediff($end, $start)) . "\n"; print scalar(%FOO)."\n"; } __END__ F:\dev>perl -le"print `perl benchy.txt`,' ' for 1..10" Processing time was... 7 wallclock secs ( 7.05 usr + 0.00 sys = 7.05 CPU) Processing time was... 1 wallclock secs ( 0.60 usr + 0.00 sys = 0.60 CPU) Processing time was... 0 wallclock secs ( 0.53 usr + 0.00 sys = 0.53 CPU) ^C F:\dev>perl -le"print `perl benchy.txt`,' ' for 1..10" Processing time was... 7 wallclock secs ( 7.30 usr + 0.00 sys = 7.30 CPU) 20/32 Processing time was... 1 wallclock secs ( 0.55 usr + 0.00 sys = 0.55 CPU) 23/64 Processing time was... 0 wallclock secs ( 0.65 usr + 0.00 sys = 0.65 CPU) 23/64 Processing time was... 7 wallclock secs ( 7.27 usr + 0.00 sys = 7.27 CPU) 20/32 Processing time was... 1 wallclock secs ( 0.54 usr + 0.00 sys = 0.54 CPU) 23/64 Processing time was... 0 wallclock secs ( 0.64 usr + 0.00 sys = 0.64 CPU) 23/64 Processing time was... 7 wallclock secs ( 7.19 usr + 0.00 sys = 7.19 CPU) 20/32 Processing time was... 1 wallclock secs ( 0.55 usr + 0.00 sys = 0.55 CPU) 23/64 Processing time was... 1 wallclock secs ( 0.63 usr + 0.00 sys = 0.63 CPU) 23/64 Processing time was... 7 wallclock secs ( 7.21 usr + 0.00 sys = 7.21 CPU) 20/32 Processing time was... 0 wallclock secs ( 0.54 usr + 0.00 sys = 0.54 CPU) 23/64 Processing time was... 1 wallclock secs ( 0.63 usr + 0.00 sys = 0.63 CPU) 23/64 Processing time was... 7 wallclock secs ( 7.15 usr + 0.00 sys = 7.15 CPU) 20/32 Processing time was... 1 wallclock secs ( 0.55 usr + 0.00 sys = 0.55 CPU) 23/64 Processing time was... 0 wallclock secs ( 0.63 usr + 0.00 sys = 0.63 CPU) 23/64 Processing time was... 7 wallclock secs ( 7.30 usr + 0.00 sys = 7.30 CPU) 20/32 Processing time was... 1 wallclock secs ( 0.54 usr + 0.00 sys = 0.54 CPU) 23/64 Processing time was... 1 wallclock secs ( 0.64 usr + 0.00 sys = 0.64 CPU) 23/64 Processing time was... 8 wallclock secs ( 7.19 usr + 0.00 sys = 7.19 CPU) 20/32 Processing time was... 0 wallclock secs ( 0.54 usr + 0.00 sys = 0.54 CPU) 23/64 Processing time was... 1 wallclock secs ( 0.63 usr + 0.00 sys = 0.63 CPU) 23/64 Processing time was... 7 wallclock secs ( 7.30 usr + 0.00 sys = 7.30 CPU) 20/32 Processing time was... 1 wallclock secs ( 0.54 usr + 0.00 sys = 0.54 CPU) 23/64 Processing time was... 0 wallclock secs ( 0.63 usr + 0.00 sys = 0.63 CPU) 23/64 Processing time was... 7 wallclock secs ( 7.23 usr + 0.00 sys = 7.23 CPU) 20/32 Processing time was... 1 wallclock secs ( 0.53 usr + 0.00 sys = 0.53 CPU) 23/64 Processing time was... 1 wallclock secs ( 0.63 usr + 0.00 sys = 0.63 CPU) 23/64 Processing time was... 8 wallclock secs ( 7.21 usr + 0.00 sys = 7.21 CPU) 20/32 Processing time was... 0 wallclock secs ( 0.54 usr + 0.00 sys = 0.54 CPU) 23/64 Processing time was... 1 wallclock secs ( 0.64 usr + 0.00 sys = 0.64 CPU) 23/64 F:\dev>

 
______crazyinsomniac_____________________________
Of all the things I've lost, I miss my mind the most.
perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"


In reply to (crazyinsomniac: %ENV equals overhead) Re: $ENV {'FOO'} $foo by crazyinsomniac
in thread $ENV {'FOO'} $foo by coreolyn

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.