Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Benchmark time :)

use strict; use warnings; use Benchmark qw(cmpthese); my %hash = ( 1 => 'one' , 2 => 'two' , 3 => 'three' ); cmpthese (-1, { 'orig' => sub {orig ()}, 'roy' => sub {roy ()}, 'GF' => sub {GF ()}, 'VS' => sub {VS ()}, 'davido' => sub {davido ()}, 'sneekyGF' => sub {sneekyGF ()}, 'sneekyDuff' => sub {sneekyDuff ()}, } ); sub orig { my (@one, @two); foreach ( keys %hash ) { push @one , $hash{$_}; push @two, $_; } } sub roy { my (@one, @two); push @one, values %hash; push @two, keys %hash; } sub GF { my (@one, @two); (push @one , $hash{$_}), push @two, $_ foreach ( keys %hash ); } sub VS { my (@one, @two); @one = values %hash; @two = keys %hash; } sub davido { my( @one ) = @hash{ my( @two ) = keys %hash }; } sub sneekyGF { my (@one, @two); --$| ? push @one, $_ : push @two, $_ foreach %hash; } sub sneekyDuff { my (@one, @two); push @{--$| ? \@one : \@two}, $_ for %hash; } sub BUK { my (@one, @two); 1 while ( $one[@one], $two[@two] ) = each %hash; }

Results:

Rate sneekyDuff BUK sneekyGF orig GF roy + VS davido sneekyDuff 55138/s -- -3% -20% -40% -40% -52% - +54% -55% BUK 57031/s 3% -- -18% -38% -38% -51% - +52% -53% sneekyGF 69161/s 25% 21% -- -25% -25% -40% - +42% -43% orig 92056/s 67% 61% 33% -- -0% -21% - +23% -25% GF 92056/s 67% 61% 33% 0% -- -21% - +23% -25% roy 115883/s 110% 103% 68% 26% 26% -- +-3% -5% VS 119184/s 116% 109% 72% 29% 29% 3% + -- -2% davido 122008/s 121% 114% 76% 33% 33% 5% + 2% --

Being sneeky doesn't pay :)

Update for BrowserUK version


DWIM is Perl's answer to Gödel

In reply to Re: Simplifying for loop and applying multiple push function by GrandFather
in thread Simplifying for loop and applying multiple push function by jesuashok

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-24 18:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found