Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^4: Rewrite Program Using Arrays

by ikegami (Pope)
on Mar 27, 2012 at 20:54 UTC ( #962025=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Rewrite Program Using Arrays
in thread Rewrite Program Using Arrays

Get rid of a scope, use preinc instead of postinc.

sub ikegami { my %wordcount; ++$wordcount{$_} for split ' ', $line; }
                  Rate loop with vars      with map loop sans vars       ikegami
loop with vars  8324/s             --          -19%           -20%          -22%
with map       10241/s            23%            --            -1%           -4%
loop sans vars 10370/s            25%            1%             --           -3%
ikegami        10666/s            28%            4%             3%            --

(Post-increment in void context is optimised to pre-increment, but it's not in void context in "with map".)


Comment on Re^4: Rewrite Program Using Arrays
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2014-09-16 15:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (33 votes), past polls