Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I've done some benchmarking of the three options (not including lima1's suggestion of suffix-trees): sequential regular expressions, sequential index's, and merging the regular expressions together using Regexp::Assemble. I'm not great at writing benchmarks, so perhaps this script is simplistic, and I'd appreciate comments on how to improve it. Nevertheless, here are the results:

Regexp : 230 wallclock secs (229.86 usr + 0.06 sys = 229.92 CPU) Index : 22 wallclock secs (21.47 usr + 0.01 sys = 21.48 CPU) Merged : 663 wallclock secs (663.73 usr + 0.17 sys = 663.90 CPU)

So it appears that even without forking the indexing approach is much faster for exact matches. Here's the benchmarking code I used.

use strict; use Bio::SeqIO; use Benchmark; use Regexp::Assemble; use Carp; my $seqio = Bio::SeqIO->new( -file => "chrY.fa.masked", -format => "fasta" ); my $seq = $seqio->next_seq(); my $sequence = $seq->seq(); my @strings = ( 'CACGTG', 'GTGCAC' ); my $t0 = new Benchmark; for (1..100) { foreach my $string (@strings) { my $len = length($string); while ($sequence =~ /$string/g) { my $val = pos($seque +nce) - $len; } } } my $t1 = new Benchmark; my $t2 = new Benchmark; for (1..100) { foreach my $string (@strings) { my $pos = 0; my $len = length($string); while ( ($pos = index($sequence, $string, $pos)) >= 0 +) { my $val = substr($sequence, $pos, $len); $pos += $len; } } } my $t3 = new Benchmark; my $t4 = new Benchmark; for (1..100) { my $ra = Regexp::Assemble->new(); $ra->add(@strings); while ( $sequence =~ /$ra/g) { my $val = pos($sequence) - 6; } } my $t5 = new Benchmark; my $td1 = timediff($t1, $t0); my $td2 = timediff($t3, $t2); my $td3 = timediff($t5, $t4); print 'Regexp : ', timestr($td1), "\n"; print 'Index : ', timestr($td2), "\n"; print 'Merged : ', timestr($td3), "\n";

In reply to Re: Multiple Regex's on a Big Sequence - Benchmark by bernanke01
in thread Multiple Regex's on a Big Sequence by bernanke01

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-20 01:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found