Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Curious find while comparing grep, map, and smart match...

by jwkrahn (Monsignor)
on Mar 27, 2013 at 02:13 UTC ( #1025616=note: print w/ replies, xml ) Need Help??


in reply to Curious find while comparing grep, map, and smart match...

redo if ( @gArray && grep { /$rInt/ } @gArray ); ... redo if ( @mArray && map { /$rInt/ } @mArray ); ... redo if ( @sArray && $rInt ~~ @sArray );

The three are not equivalent.    grep and map use regular expressions and have code blocks while the other does not.    Try it like this:

redo if @gArray && grep /$rInt/, @gArray; ... redo if @mArray && map /$rInt/, @mArray; ... redo if @sArray && /$rInt/ ~~ @sArray;


Comment on Re: Curious find while comparing grep, map, and smart match...
Select or Download Code
Re^2: Curious find while comparing grep, map, and smart match...
by dbuckhal (Monk) on Mar 27, 2013 at 03:17 UTC

    Wow, that, and using word boundaries from tye's hint, made a significant difference!

    before:

    Benchmark: timing 2500 iterations of grepGen, mapGen, smartGen... grepGen: 23 wallclock secs (22.51 usr + 0.00 sys = 22.51 CPU) @ 11 +1.06/s (n=2500) mapGen: 11 wallclock secs (11.42 usr + 0.00 sys = 11.42 CPU) @ 21 +8.93/s (n=2500) smartGen: 1 wallclock secs ( 1.05 usr + 0.00 sys = 1.05 CPU) @ 23 +92.34/s (n=2500)

    after:

    Benchmark: timing 2500 iterations of grepGen, mapGen, smartGen... grepGen: 14 wallclock secs (13.70 usr + 0.00 sys = 13.70 CPU) @ 18 +2.52/s (n=2500) mapGen: 13 wallclock secs (13.57 usr + 0.00 sys = 13.57 CPU) @ 18 +4.20/s (n=2500) smartGen: 2 wallclock secs ( 1.19 usr + 0.00 sys = 1.19 CPU) @ 21 +07.93/s (n=2500)

    That really narrowed the gap between grep and map.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2014-07-26 00:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls