"n00m" <[EMAIL PROTECTED]> schreef in bericht news:[EMAIL PROTECTED]
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;
   }

first of all I would rewrite the C loop to:

int main() {
   int i=0;
   while (fgets(vs[i],999,fp))
       ++i;
}

but I think that the difference comes from what you do in the beginning of the C source:

char vs[1002000][99];

this reserves 99,198,000 bytes so expect a lot of cache trashing in the C code!

Is there an implementation of f.readlines on the internet somewhere? interested to see in how they implemented it. I'm pretty sure they did it smarter than just reserve 100meg of data :)


   fclose(fp);
   cout << i << endl;
   cout << clock()/CLOCKS_PER_SEC << endl;

   int m;
   cin >> m;
   cout << vs[m];
   system("pause");
return 0;
}

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to