Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: question about reg exp engine

by broomduster (Priest)
on Aug 03, 2008 at 23:55 UTC ( [id://701949]=note: print w/replies, xml ) Need Help??


in reply to Re^2: question about reg exp engine
in thread question about reg exp engine

yes I have a typo in the post. It shoud be ^\s, but that still doesn't give me an answer.
If you fix that typo and then run Benchmarks, I think you will see that they are about the same speed. I see speed differences of 0-3% with the typo fixed, and 20-25% with the typo in place.... probably because some optimization is possible when the regex says "beginning of string" and not '^' in an arbitrary place in the string.

Replies are listed 'Best First'.
Re^4: question about reg exp engine
by GrandFather (Saint) on Aug 04, 2008 at 00:04 UTC

    Show your benchmark. I see about a 75x difference between the single regex and the multiple regex solutions offered by the OP.

    Note that benchmarks are rather like statistics: Lies, damn lies and benchmarks.


    Perl reduces RSI - it saves typing
      I have a feeling I may be about to learn something... ;-)
      use strict; use warnings; use Benchmark qw( cmpthese ); my $results = cmpthese( -10, { 'r3' => sub { my $string = " stuff "; $string =~ s/^\s//g; $string =~ s/\s$//g; $string =~ s/\s+$//g; }, 'r1' => sub { my $string = " stuff "; $string =~ s/^\s|\s$|\s+$//g; }, } );

      Rate r1 r3 r1 295926/s -- -1% r3 299980/s 1% --

      Updated: Now that I see GrandFather's detailed Benchmark below, I see that my error was to use a short string. When I change to
      my $string = (' ' x 1000) . 'x' . (' ' x 1000);
      matching GrandFather's, I get the following:
      Rate r3 r1 r3 61890/s -- -79% r1 297607/s 381% --
      So Lies, damn lies, and benchmarks (with the wrong data), indeed.

        Changing "  stuff  " to (' ' x 1000) . 'x' . (' ' x 1000) gives:

        Rate r1 r3 r1 1849/s -- -99% r3 166166/s 8888% --

        It is important that a benchmark test what you think it is testing so what you think is being tested must entail a significant portion of the benchmark's processing time.

        Update: BTW, my result for your original benchmark was:

        Rate r1 r3 r1 767220/s -- -10% r3 855450/s 11% --

        Perl reduces RSI - it saves typing

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-03-29 12:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found