I was inspired to benchmark your advice. In my testing environment, I was astonished to find out that the speed increases as you collect more and more letters (first letters, then second letters, etc.) in your look-ahead.
Benchmark: timing 200 iterations of lookahead1, lookahead3, lookahead4 +, lookahead5, nolookahead... lookahead1: 3 wallclock secs ( 2.93 usr + 0.00 sys = 2.93 CPU) @ 68 +.26/s (n=200) lookahead3: 2 wallclock secs ( 2.23 usr + 0.00 sys = 2.23 CPU) @ 89 +.69/s (n=200) lookahead4: 2 wallclock secs ( 2.03 usr + 0.00 sys = 2.03 CPU) @ 98 +.52/s (n=200) lookahead5: 2 wallclock secs ( 2.00 usr + 0.00 sys = 2.00 CPU) @ 10 +0.00/s (n=200) nolookahead: 7 wallclock secs ( 6.30 usr + 0.00 sys = 6.30 CPU) @ 3 +1.75/s (n=200)
I used the following code and used this document as my input.
#!/usr/bin/perl use strict; use warnings; use Benchmark; undef $/; my $text = <>; # "progressive", "great", "interlacing", "really" and "wonder" are in +the document my $words = q{ featuring | blossom | great | interlacing | really | linux | thought | wonder | progressive }; timethese(200, { lookahead5 => sub { 1 while $text =~ m{(?= [fbgrltwpi][elihorn][aoent][tsaludge][ustrlxger] )( $words )}gix; }, lookahead4 => sub { 1 while $text =~ m{(?= [fbgrltwpi][elihorn][aoent][tsaludge] )( $words )}gix; }, lookahead3 => sub { 1 while $text =~ m{(?= [fbgrltwpi][elihorn][aoent] )( $words )}gix; }, lookahead1 => sub { 1 while $text =~ m{(?= [fbgrltwpi] )( $words )}gix; }, nolookahead => sub { 1 while $text =~ m{( $words )}gix; }, });

In reply to Re^2: Fast searching of multiple substrings in a string by betterworld
in thread Fast searching of multiple substrings in a string by dgaramond2

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.