Python(2.5) reads an input file FASTER than pure C(Mingw)
n00m
n00m at narod.ru
Sat Apr 26 11:10:09 EDT 2008
Both codes below read the same huge(~35MB) text file.
In the file > 1000000 lines, the length of each line < 99 chars.
Stable result:
Python runs ~0.65s
C : ~0.70s
Any thoughts?
import time
t=time.time()
f=open('D:\\some.txt','r')
z=f.readlines()
f.close()
print len(z)
print time.time()-t
m=input()
print z[m]
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
char vs[1002000][99];
FILE *fp=fopen("D:\\some.txt","r");
int main() {
int i=0;
while (true) {
if (!fgets(vs[i],999,fp)) break;
++i;
}
fclose(fp);
cout << i << endl;
cout << clock()/CLOCKS_PER_SEC << endl;
int m;
cin >> m;
cout << vs[m];
system("pause");
return 0;
}
More information about the Python-list
mailing list