Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^7: Find Prefix if regex didn't match

by Anonymous Monk
on Oct 31, 2012 at 14:36 UTC ( #1001675=note: print w/ replies, xml ) Need Help??


in reply to Re^6: Find Prefix if regex didn't match
in thread Find Prefix if regex didn't match

Show code and prove it, its easy

#!/usr/bin/perl -- use Benchmark qw/ cmpthese /; print "$]\n"; cmpthese( -3, { circumcised => sub { my $what = 'WWWA'; $what =~ /AB.*Z/gc; # fail one $what .='DBBBABC'; pos($what) = 8; $what =~ /AB.*Z/gc; # fail another return; }, uncut => sub { my $what = 'WWWA'; $what =~ /AB.*Z/gc; # fail one $what .='DBBBABC'; $what =~ /AB.*Z/gc; # fail another return; }, }, ); print "\n\n"; cmpthese( -3, { circumcised => sub { my $what = 'WWWA'; $what =~ /AB.*Z/gc; # fail one $what .='DBBBABCZ'; pos($what) = 8; $what =~ /AB.*Z/gc; # match one return; }, uncut => sub { my $what = 'WWWA'; $what =~ /AB.*Z/gc; # fail one $what .='DBBBABCZ'; $what =~ /AB.*Z/gc; # match one return; }, }, ); print "\n\n"; cmpthese( -3, { circumcised => sub { my $what = 'WWWA'; $what =~ /AB.*Z/gc; # fail one $what .='DBBBABCZ'; substr $what, 0, 8, ''; $what =~ /AB.*Z/gc; # match one return; }, uncut => sub { my $what = 'WWWA'; $what =~ /AB.*Z/gc; # fail one $what .='DBBBABCZ'; $what =~ /AB.*Z/gc; # match one return; }, }, ); print "\n\n"; cmpthese( -3, { circumcised => sub { my $what = 'WWWA'; $what =~ /AB.*Z/; # fail one $what .='DBBBABCZ'; substr $what, 0, 8, ''; $what =~ /AB.*Z/; # match one return; }, uncut => sub { my $what = 'WWWA'; $what =~ /AB.*Z/; # fail one $what .='DBBBABCZ'; $what =~ /AB.*Z/; # match one return; }, }, ); print "\n\n"; __END__
5.014001 Rate circumcised uncut circumcised 370001/s -- -70% uncut 1245010/s 236% -- Rate circumcised uncut circumcised 301014/s -- -41% uncut 506153/s 68% -- Rate circumcised uncut circumcised 398024/s -- -19% uncut 492750/s 24% -- Rate circumcised uncut circumcised 554597/s -- -26% uncut 749156/s 35% --


Comment on Re^7: Find Prefix if regex didn't match
Select or Download Code
Re^8: Find Prefix if regex didn't match
by demoralizer (Acolyte) on Nov 06, 2012 at 12:16 UTC
    Sorry, I haven't found any time spending on this topic the last days...

    Your benchmarks are not exactly what I thought about, what I have in my mind is:
    #!/usr/bin/perl -- use Benchmark qw/ cmpthese /; print "$]\n"; my $what1 = 'WWWA'; my $what2 = $what1; cmpthese( -3, { circumcised => sub { $what1 =~ /EB.*Z/; # fail one $what1 .='DBBBABC'; substr $what1, 0, 8, ''; $what1 =~ /EB.*Z/; # fail another return; }, uncut => sub { $what2 =~ /EB.*Z/; # fail one $what2 .='DBBBABC'; $what2 =~ /EB.*Z/; # fail another return; }, }, ); print "\n\n"; __END__ 5.010001 Rate uncut circumcised uncut 2735/s -- -100% circumcised 3398892/s 124179% --

      Your benchmarks are not exactly what I thought about, what I have in my mind is:

      I see :)

      But, still, neither results seems very important , network is always much slower than both

        But, still, neither results seems very important , network is always much slower than both

        Yes, that's for sure meanwhile... in a previous versions I used $rec = <$term> instead of read($term, $rec, 0xFFFF) what came in my mind when I was writing one of my replies here and what definitely was the major reason for my timing problem because the log file I receive via TCP contains many new lines what caused much more matchings than necessary... so asking questions here has already fulfilled its purpose :)

        But what has left, there is still a problem in my mind I haven't really solved yet, that is scanning for prefixes which could be a regular expression, not just a simple ASCII string. So I'm still wondering if there is really no possibility in pearl asking the regexp engine to tell me at which position it started matching when it reached the end of given string the first time even if it hasn't reached end of expression yet...

        By the way many thanks for all your help, according to your astonishing response time I guess you live in front of your computer? ;)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2014-09-23 05:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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











    Results (210 votes), past polls