Two sets of code files are written, and the code functions in the group are the same:
testv.pl vs Testv.cpp
testreg.pl vs Testreg.cpp
The code is as follows:
testreg.cpp/////////
#include <iostream>
#include <fstream>
#include <regex>
using namespace Std;
int main (int argv, char * * argc)
{
FStream in (argc[1], fstream::in);
int Line_Count;
String line_content;
Regex reg ("[ATCG]");
while (Getline (in, line_content))
{
line_count++;
if (line_count% 4 = = 2)
{
if (Regex_search (Line_content, Reg))
{
cout<<1<<endl;
}
}
}
return 0;
}
testreg.pl/////////
#!/usr/bin/perl
Use strict;
Use 5.010;
my $file = shift;
Open SEQ, ' < ', $file or Die "$!";
while (<SEQ>) {
Chomp
if ($.% 4 = = 2) {
if (/[atcg]/) {
Say 1;
}
}
}
testv.cpp/////////
#include <iostream>
#include <fstream>
#include <unordered_map>
using namespace Std;
int main (int argv, char * * argc)
{
FStream in (argc[1], fstream::in);
int Line_Count;
String line_content;
typedef unordered_map<string, int> mapdef;
Mapdef Mymap;
while (Getline (in, line_content))
{
line_count++;
if (line_count% 4 = = 2)
{
mymap[line_content]++;
}
}
Cout<<mymap.size () <<endl;
return 0;
}
testv.pl/////////
#!/usr/bin/perl
Use strict;
Use 5.010;
my $file = shift;
Open SEQ, ' < ', $file or Die "$!";
My%hash;
while (<SEQ>) {
Chomp
if ($.% 4 = = 2) {
$hash {$_}++;
}
}
Say scalar (keys%hash);
Using the shell command, calculate the run time with the following results:
Time Perl testv.pl Input
Time./a.out Input
Time Perl testreg.pl Input | Wc-l
Time./a.out Input | Wc-l
|
Real |
User |
Sys |
|
testv.pl |
0m0.141s |
0m0.121s |
0m0.011s |
|
Testv.cpp |
0m0.077s |
0m0.054s |
0m0.012s |
|
testreg.pl |
0m0.142s |
0m0.122s |
0m0.006s |
|
Testreg.cpp |
0m0.251s |
0m0.104s |
0m0.137s |
|
Where input is a FASTQ file that contains a 54914DNA sequence.
It can be seen that in the case of regular expression operations, C + + obviously does not dominate, to the card one or two face output results
Comparison between C + + and Perl in the computation speed of regular expressions