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

•Re: Check whether your hash keys have random order

by merlyn (Sage)
on Sep 08, 2003 at 14:00 UTC ( #289772=note: print w/ replies, xml ) Need Help??

in reply to Check whether your hash keys have random order

Why launch a separate process?

use Config; my $ccflags = $Config{ccflags}; ...
No need to fork for this!

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Comment on •Re: Check whether your hash keys have random order
Download Code
Replies are listed 'Best First'.
Re: •Re: Check whether your hash keys have random order
by liz (Monsignor) on Sep 08, 2003 at 16:31 UTC
    I was trying to save memory by not having to load But because of your remark, I decided to do a Benchmark:
    Benchmark: timing 1000 iterations of open, use...
     open: 38 wallclock secs ( 2.62 usr  0.00 sys + 16.14 cusr 12.96 csys = 31.72 CPU) @ 381.68/s (n=1000)
      use: 14 wallclock secs (13.15 usr +  0.00 sys = 13.15 CPU) @ 76.05/s (n=1000)

    This surprised me a lot!. The fork() approach with open() seems to be 5 times as fast as loading!

    Alas, I think I stumbled upon a bug / feature / problem of Benchmark: apparently, only "usr" CPU is taken into account when calculating the number of runs/second, and the "usr" CPU is of course a lot less than with fork/open than it is with use.

    Still, the fork/open approach only takes 2.5 times as much CPU as loading I wonder if that is a testament of the efficiency of fork(), or the slowness of ;-)

    The code:

    use Benchmark; timethese( 1000, { open => sub { open my $handle, $^X.' -V:ccflags |'; my $ccflags = <$handle>; delete $INC{''}; }, use => sub { require Config; Config->import; my $ccflags = $Config{ccflags}; delete $INC{''}; }, } );


      The use version creates a tied perl hash, employing caching ... while the other version doesn't bother to do that and simply matches on a scalar.
      perl -d:Trace -V:ccflags >> foreach(@_){ >> config_re($_), next if /\W/; >> my $v=(exists $Config{$_}) ? $Config{$_} : 'UNKNOW +N'; >> exists($_[0]->{$_[1]}) or >> return $_[0]->{$_[1]} if (exists $_[0]->{$_[1]}) +; >> my($value, $start, $marker, $quote_type); >> $quote_type = "'"; >> if ($_[1] eq 'byteorder') { >> $marker = "$_[1]="; >> $start = index($config_sh, "\n$marker$quote_type") +; >> if ($start == -1) { >> return undef if ( ($start == -1) && # in case it' +s first >> if ($start == -1) { >> $start += length($marker) + 2; >> $value = substr($config_sh, $start, >> if ($quote_type eq '"') { >> $value = undef if $value eq 'undef'; >> $_[0]->{$_[1]} = $value; # cache it >> return $value; >> $v='undef' unless defined $v; >> print "$_='$v';\n"; ccflags='-nologo -O1 -MD -DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT -DHAV +E_DES_FCRYPT -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -D PERL_MSVCRT_READFIX'; >> foreach(@_){
      Maybe i'm wrong ...

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2015-11-28 00:27 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (735 votes), past polls