To illustrate the speed difference I wrote a small benchmark that assembles 500 random strings of length 5 to 15 into a regex, and matches that against a random string with 1 million characters. Here's the result:
# perl 5.10.0: timethis 10: 0 wallclock secs ( 0.33 usr + 0.00 sys = 0.33 CPU) @ 3 +0.30/s (n=10) (warning: too few iterations for a reliable count) # perl 5.8.8: timethis 10: 79 wallclock secs (78.92 usr + 0.04 sys = 78.96 CPU) @ +0.13/s (n=10)

This is on Linux, but I guess the results on Windows are similar. You see that in this case perl5.10.0 takes less than a second, while perl5.8.8 takes over a minute.

I also tried it with a shorter target (100 chars) and more iterations, and the speed differences are similar.

And here's the Benchmark:

use strict; use warnings; my @alphabet = ('a'..'z', 'A'..'Z', ' '); sub random_string { my $length = int shift; return join '', map { @alphabet[int rand(@alphabet)] } 1..$length; } my $re = join '|', map { random_string(5+rand(10)) } 1..500; my $target = random_string(1e2); use Benchmark qw(timethis); timethis(100_000, sub { $target =~ m/$re/ })

In reply to Re^4: Efficient regex matching with qr//; Can I do better? (Benchmark) by moritz
in thread Efficient regex matching with qr//; Can I do better? by kruppy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.