in reply to Re^2: better (faster) way of writing regexp
in thread better (faster) way of writing regexp
I'm not sure why you have the regex engine check if each character is not a newline in isook. Use the "s" modifier!
Interesting about pack. I heard the overhead to start the regex engine went up in 5.10, but it seems rather minor when put into perspective. ...except I can't replicate your results.
use strict; use warnings; use Benchmark qw(:all); print("This is Perl $]\n"); my %tests = ( repeat => 'my ($y,$m,$d) = $date =~ /(\\d\\d\\d\\d)(\\d\\d)(\\d\\d +)/;', range => 'my ($y,$m,$d) = $date =~ /(\\d{4})(\\d{2})(\\d{2})/;', isook => 'my ($y,$m,$d) = $date =~ /(....)(..)(..)/s;', unpack => 'my ($y,$m,$d) = unpack "A4 A2 A2", $date;', ); # These don't result in any opcodes. $_ = 'use strict; use warnings; our $date; '.$_ for values(%tests); our $date = '20091202'; my $results = cmpthese(-3, \%tests);
This is Perl 5.010000 Rate range repeat isook unpack range 405773/s -- -6% -8% -46% repeat 432956/s 7% -- -2% -43% isook 441233/s 9% 2% -- -42% unpack 757010/s 87% 75% 72% -- This is Perl 5.010000 Rate range isook repeat unpack range 398141/s -- -7% -7% -47% isook 427913/s 7% -- -0% -43% repeat 429311/s 8% 0% -- -43% unpack 751802/s 89% 76% 75% -- This is Perl 5.010000 Rate range repeat isook unpack range 415595/s -- -7% -8% -45% repeat 445365/s 7% -- -1% -41% isook 449974/s 8% 1% -- -40% unpack 754290/s 81% 69% 68% --
The faster way seems to be using the capture made of dots as in "isook"
You haven't shown that. Any difference less than 5% should be ignored. It's within the error margin.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: better (faster) way of writing regexp
by JavaFan (Canon) on Dec 02, 2009 at 18:19 UTC | |
by ikegami (Patriarch) on Dec 02, 2009 at 18:33 UTC | |
|
Re^4: better (faster) way of writing regexp
by Marshall (Canon) on Dec 03, 2009 at 07:52 UTC | |
by ikegami (Patriarch) on Dec 03, 2009 at 17:42 UTC | |
by Marshall (Canon) on Dec 03, 2009 at 22:28 UTC | |
by ikegami (Patriarch) on Dec 03, 2009 at 22:38 UTC |