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":



  • 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.