Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^5: question about reg exp engine

by broomduster (Priest)
on Aug 04, 2008 at 00:11 UTC ( [id://701951]=note: print w/replies, xml ) Need Help??


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

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.

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

    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
      I didn't see this reply before I Updated above, but now we're in the same direction, even if the magnitude of difference is off. As I said earlier, the largest difference I saw for the short string was 3% (about a dozen runs, looking back).

      BTW, I can confirm your observation about the penalty associated with 'nibble' vs. 'swallow' vs. both.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2024-04-25 08:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found