
Originally Posted by
VladimirF
My guess is that code like that should execute at the speed of file I/O.
I know I can copy a 1GB file in about 30 seconds, so 11 minutes sounds like WAY too much.
Could you comment out everything in your code except for I/O and see how long that takes?
Do you mind posting your code and a sample data file?
Here is the final code
Code:
#include <map>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <time.h>
using namespace std;
int main( int argc, char *argv[] ) {
if ( argc == 1 ) {
fprintf(stderr, "Usage: xytest <input> <output>\n");
return 1;
}
time_t start,end;
double diff;
time (&start);
map<int, int> mapTest;
ifstream fin(argv[1]);
string tempLine;
int x1, x2;
while ( fin >> tempLine >> x1 >> x2 ) {
getline(fin,tempLine);
for ( int i = x1; i <= x2; ++i ) {
++mapTest[i];
}
}
fin.close();
ofstream fout(argv[2]);
for ( map<int, int>::iterator i = mapTest.begin(), end = mapTest.end(); i != end; ++i ) {
fout << i->first << '\t' << i->second << '\n';
}
fout.close();
time (&end);
diff = difftime(end, start);
printf("Running time: %.2lf\n",diff);
return 0;
}
Some lines in the input file is like this
Code:
a1 35952485 35952517 2 0 -
a1 66611781 66611813 15 0 +
a1 154104890 154104922 10 0 +
a1 224631511 224631543 6 0 -
and there are 25501054 lines similar like that in the file. The size of file is 1141987065.
Let me try your suggestion to see what results are.