Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

(crazyinsomniac: %ENV equals overhead) Re: $ENV {'FOO'} $foo

by crazyinsomniac (Prior)
on Feb 14, 2002 at 23:14 UTC ( [id://145576]=note: print w/replies, xml ) Need Help??


in reply to $ENV {'FOO'} $foo

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;"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://145576]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-25 08:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found