Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Perl: porters
[perl #32331] grep {/PATTERN/} is slow
 

Index | Next | Previous | View Flat


perlbug-followup at perl

Apr 29, 2012, 6:49 PM


Views: 46
Permalink
[perl #32331] grep {/PATTERN/} is slow

On Fri Dec 03 11:22:39 2004, ajs wrote:
> Sorry, I submitted before I was done. My final version of the test:
>
> use Benchmark qw /cmpthese/;
>
> our @array = 101 .. 20000;
> our $b1;
> our $b2;
>
> cmpthese -2 => {
> grep_re_expr => '$::b1 = grep /50/, @::array',
> grep_re_blck => '$::b1 = grep {/50/} @::array',
> grep_re_subr => '$::b2 = grep {is50($_)} @::array',
> };
>
> die unless $b1 == $b2;
>
> sub is50 {
> return ($_[0] =~ /50/);
> }
>
> I also tried:
>
> our $p = qr{^50$};
>
> and then something like:
>
> grep_re_blck => '$::b1 = grep {/$p/} @::array',
>
> which was very slightly faster (relative to the expr version with the
> pre-compiled regexp), so this makes me suspect repeated re-parsing of
> the regexp.


This is still present in blead; But as far as I can tell, the slowdown
is because the block version needs to create and enter/leave a scope,
while the expression version has no such penalty; So unless I'm wrong, I
think this has to be marked as WontFix.


---
via perlbug: queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=32331

Subject User Time
[perl #32331] grep {/PATTERN/} is slow perlbug-followup at perl Apr 29, 2012, 6:49 PM
    [perl #32331] grep {/PATTERN/} is slow perlbug-followup at perl Apr 30, 2012, 5:53 AM

  Index | Next | Previous | View Flat
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.