N
n00m
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,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;
}
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,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;
}