Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

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

Yes, that is what I mean. Consider this benchmark

#!/usr/bin/perl -- use strict; use warnings; use Benchmark qw(cmpthese); print "\n$]\n"; our $data; for my $range ( 1_000 , 2_000 , 10_000 , 100_000 ){ $data = join '',map { ( qw' T A C G ' )[ $_ % 4 ] } 0 .. $range; print "\n$range\n"; cmpthese (-3, { SplitAssign => \&SplitAssign, SplitRegex => \&SplitRegex, Substitution => \&Substitution, }); print "##" x 33, "\n\n"; } sub SplitAssign { my @data = split //, $data; for my $char ( @data ){ if( $char eq 'T' ){ $char = 'G'; } elsif( $char eq 'A' ){ $char = 'T'; } elsif( $char eq 'C' ){ $char = 'A'; } elsif( $char eq 'G' ){ $char = 'C'; } } my $newData = join '', @data; return; } sub SplitRegex { my @data = split //, $data; for my $char ( @data ){ if( $char eq 'T' ){ $char =~ s/T/G/; } elsif( $char eq 'A' ){ $char =~ s/A/T/; } elsif( $char eq 'C' ){ $char =~ s/C/A/; } elsif( $char eq 'G' ){ $char =~ s/G/C/; } } my $newData = join '', @data; return; } sub Substitution { my $newData = $data; $newData =~ s/(.)/ my $char = $1; if( $char eq 'T' ){ $char = 'G'; } elsif( $char eq 'A' ){ $char = 'T'; } elsif( $char eq 'C' ){ $char = 'A'; } elsif( $char eq 'G' ){ $char = 'C'; } $char; /ge; return; } __END__

And the results

5.012002 1000 Rate Substitution SplitRegex SplitAssign Substitution 299/s -- -9% -37% SplitRegex 329/s 10% -- -31% SplitAssign 478/s 60% 45% -- ################################################################## 2000 Rate Substitution SplitRegex SplitAssign Substitution 147/s -- -6% -34% SplitRegex 157/s 7% -- -30% SplitAssign 224/s 53% 43% -- ################################################################## 10000 Rate SplitRegex Substitution SplitAssign SplitRegex 27.8/s -- -3% -25% Substitution 28.6/s 3% -- -23% SplitAssign 37.2/s 34% 30% -- ################################################################## 100000 Rate SplitRegex SplitAssign Substitution SplitRegex 1.91/s -- -16% -28% SplitAssign 2.29/s 20% -- -13% Substitution 2.64/s 38% 15% -- ##################################################################

For the length of string in your program (1702) using assignment (SplitAssign ) is faster than using regex (SplitRegex)


In reply to Re^3: Increasing the efficiency of a viral clonal expansion model by Anonymous Monk
in thread Increasing the efficiency of a viral clonal expansion model by ZWcarp

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 romping around the Monastery: (4)
As of 2024-04-25 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found