in reply to Re: Removing Flanking "N"s in a DNA String
in thread Removing Flanking "N"s in a DNA String
Also, your regex is quite inefficient, as perl has jump through hoops to save the value captured in the parentheses. It's quicker to "top and tail" the string over two lines. Three times quicker in fact...
#!/perl -w use strict; use Benchmark; timethese(200000, { 'single' => sub { my $dna = "NNNNATCGNNNTCGANNN"; $dna =~ s/^N*(.*?)N*$/$1/; }, 'twin' => sub { my $dna = "NNNNATCGNNNTCGANNN"; $dna =~ s/^N*//; $dna =~ s/N*$//; }, }); __OUTPUT__ Benchmark: timing 200000 iterations of single, twin... single: 3 wallclock secs ( 2.95 usr + 0.00 sys = 2.95 CPU) @ 67 +704.81/s (n=200000) twin: 1 wallclock secs ( 0.83 usr + 0.00 sys = 0.83 CPU) @ 24 +0963.86/s (n=200000)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Removing Flanking "N"s in a DNA String
by BrowserUk (Patriarch) on Nov 07, 2005 at 15:47 UTC | |
by reasonablekeith (Deacon) on Nov 07, 2005 at 16:11 UTC | |
|
Re^3: Removing Flanking "N"s in a DNA String
by Perl Mouse (Chaplain) on Nov 07, 2005 at 16:05 UTC |