J
jeffrey.bigham
Hello,
I'm writing a program that needs to read input line by line and analyze
each, and it needs to be as efficient as possible. I wrote the
following sample program that works, but is 10 times slower than a Perl
equivalent on a large input (~212 Mb). There has to be something wrong
- can anyone help me fix it? I've included both at the bottom of my
post and I compile with g++ -03 cin_test.C
Thanks!
Jeff
#include <string>
#include <iostream>
using namespace std;
int main() {
string my_string;
while(cin) {
getline(cin, my_string);
}
}
The Perl "equivalent" that I used (verbatim) is:
while (<>) { print if /someregex/; }
I'm writing a program that needs to read input line by line and analyze
each, and it needs to be as efficient as possible. I wrote the
following sample program that works, but is 10 times slower than a Perl
equivalent on a large input (~212 Mb). There has to be something wrong
- can anyone help me fix it? I've included both at the bottom of my
post and I compile with g++ -03 cin_test.C
Thanks!
Jeff
#include <string>
#include <iostream>
using namespace std;
int main() {
string my_string;
while(cin) {
getline(cin, my_string);
}
}
The Perl "equivalent" that I used (verbatim) is:
while (<>) { print if /someregex/; }