История изменений
Исправление demensdeum, (текущая версия) :
Прошу простить за нелепую ошибку с аллокацией, все-таки я нуб
C++
#include <iostream>
#include <fstream>
#include <regex>
#include <time.h>
using namespace std;
int main(int argc, char *argv[]) {
ifstream file("vxod.txt");
string line;
clock_t start = clock();
auto pattern = regex(R"(([^+ ]*?)([^+ ]*)[ +]+\2)");
while (getline(file, line)) {
auto output = regex_replace(line, pattern, "$1$2");
cout << output << endl;
}
double time = (double)(clock() - start) / CLOCKS_PER_SEC;
cout << "Perform time: " << time << " seconds "<< endl;
};
#!/usr/bin/perl
open D, 'vxod.txt';
open V, '>vyxod.txt';
$t = time();
while (<D>) {
s/([^+\s]*?)([^+\s]*)[\s+]+\2/$1$2/;
print;
print V;
}
$t2 = time()-$t;
print "Perform time: $t2 seconds\n"
clang++ wordcross.cpp -Ofast && ./a.out
perl -MTime::HiRes=time wordcross.perl
C++ Perform time: 0.773497 seconds
Perl Perform time: 0.317941188812256 seconds
Исправление demensdeum, :
Прошу простить за нелепую ошибку с аллокацией, все-таки я нуб
C++
#include <iostream>
#include <fstream>
#include <regex>
#include <time.h>
#include <pcre.h>
using namespace std;
int main(int argc, char *argv[]) {
ifstream file("vxod.txt");
string line;
clock_t start = clock();
auto pattern = regex(R"(([^+ ]*?)([^+ ]*)[ +]+\2)");
while (getline(file, line)) {
auto output = regex_replace(line, pattern, "$1$2");
cout << output << endl;
}
double time = (double)(clock() - start) / CLOCKS_PER_SEC;
cout << "Perform time: " << time << " seconds "<< endl;
};
#!/usr/bin/perl
open D, 'vxod.txt';
open V, '>vyxod.txt';
$t = time();
while (<D>) {
s/([^+\s]*?)([^+\s]*)[\s+]+\2/$1$2/;
print;
print V;
}
$t2 = time()-$t;
print "Perform time: $t2 seconds\n"
clang++ wordcross.cpp -Ofast && ./a.out
perl -MTime::HiRes=time wordcross.perl
C++ Perform time: 0.773497 seconds
Perl Perform time: 0.317941188812256 seconds
Исходная версия demensdeum, :
Прошу простить за нелепую ошибку с аллокацией, все-таки я нуб
C++
#include <iostream>
#include <fstream>
#include <regex>
#include <time.h>
#include <pcre.h>
using namespace std;
int main(int argc, char *argv[]) {
ifstream file("vxod.txt");
string line;
clock_t start = clock();
auto pattern = regex(R"(([^+ ]*?)([^+ ]*)[ +]+\2)");
while (getline(file, line)) {
auto output = regex_replace(line, pattern, "$1$2");
cout << output << endl;
}
double time = (double)(clock() - start) / CLOCKS_PER_SEC;
cout << "Perform time: " << time << " seconds "<< endl;
};
#!/usr/bin/perl
open D, 'vxod.txt';
open V, '>vyxod.txt';
$t = time();
while (<D>) {
s/([^+\s]*?)([^+\s]*)[\s+]+\2/$1$2/;
print;
print V;
}
$t2 = time()-$t;
print "Perform time: $t2 seconds\n"
clang++ wordcross.cpp -Ofast && ./a.out
perl -MTime::HiRes=time wordcross.perl
C++ Perform time: 0.773497 seconds
Perform time: 0.317941188812256 seconds