Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Returning regexp pattern that was used to match

by Abigail-II (Bishop)
on May 03, 2004 at 15:38 UTC ( #350051=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Returning regexp pattern that was used to match
in thread Returning regexp pattern that was used to match

but I'm concerned about speed. If its doing this for ever file on a terabyte server I'm worried about the time consumption. What do you think?
Just the fact that you hide a loop as regexp alternatives doesn't mean it's suddenly orders of a magnitude faster. In fact, it might as well be that splitting the regexp in smaller chunks is faster, because the optimizer kicks in.

Here's a benchmark:

#!/usr/bin/perl use strict; use warnings; use Benchmark qw /cmpthese/; our @regexes = ( '.*\.jpg$', '.*\.png$', 'Perl', '\.mozilla/abigail', ); our @words = `find /home/abigail`; # 38517 files. our ($c1, $c2); cmpthese -60 => { single => 'my $regex = join "|" => @regexes; $c1 = 0; for my $w (@words) { $c1 ++ if $w =~ /$regex/ }', many => '$c2 = 0; WORD: for my $w (@words) { for my $r (@regexes) { $c2 ++, next WORD if $w =~ /$r/ } }', }; die "Unequal\n" unless $c1 == $c2; __END__ s/iter single many single 4.86 -- -74% many 1.28 281% --
Now, for your particular data set results might be different. But don't assume alternatives are necessarely slower.

Abigail

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://350051]
help
Chatterbox?
shmem is grabbed by nostalgia for Bolivia
[erix]: aah, ok.
[erix]: oh well, in each life some rain must fall
[erix]: if you're interested in tsv file reading in pg, look at file_fdw
[erix]: aka: create extension if not exists file_fdw;

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (12)
As of 2018-02-23 15:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (302 votes). Check out past polls.

    Notices?