small improvements:
sub test_regexps2 { my ($seq1, $seq2, $window, $mismatch) = @_; my $retval = ''; my %cache; my @mask = (0) x (length ($seq2) - $window); for my $start (0 .. (length ($seq1) - $window)) { my $part = substr ($seq1, $start, $window); $retval .= $cache{$part} ||= do { my $regex = build_regexp ($part, $mismatch); my @res = @mask; while ($seq2 =~ m/(?=$regex)/g) { $res[ pos $seq2 ] = 1; } join '', @res, "\n"; }; } $retval; }
benchmarks for length 200, 400 and 600
200: Rate orig_poster test_regexps test_regexps2 orig_poster 9.70/s -- -51% -81% test_regexps 19.6/s 103% -- -61% test_regexps2 49.8/s 413% 153% -- 400: Rate orig_poster test_regexps test_regexps2 orig_poster 2.44/s -- -52% -84% test_regexps 5.08/s 109% -- -67% test_regexps2 15.5/s 535% 205% -- 600: Rate orig_poster test_regexps test_regexps2 orig_poster 1.06/s -- -54% -86% test_regexps 2.30/s 117% -- -70% test_regexps2 7.75/s 633% 237% --

In reply to Re^2: Speed up DNA dotplot by happy.barney
in thread Speed up DNA dotplot by Microcebus

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.