Python(2.5) reads an input file FASTER than pure C(Mingw)

Gabriel Ibanez mobile at ibinsa.com
Sun Apr 27 07:05:28 EDT 2008


I did something near like that several days ago. Instead of programming in 
C++ I did it with RM-Cobol. I used to know the times that cobol takes to 
read the file and search for resutls, and I was surprised about the time 
that Python took doing the same: really, really fast.


----- Original Message ----- 
From: "n00m" <n00m at narod.ru>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Sunday, April 27, 2008 6:28 AM
Subject: Re: Python(2.5) reads an input file FASTER than pure C(Mingw)


> One more brick.
> This time I compare list.sort() vs sort(vector<string>).
> Incredible. Python does it by 8.3s / 2.75s = 3 times faster than C++.
>
>
> import time
> f=open('D:\\v.txt','r')
> z=f.readlines()
> f.close()
> t=time.time()
> z.sort()
> print time.time()-t
> m=int(raw_input())
> print z[m]
>
>
> #include <cstdio>
> #include <cstdlib>
> #include <iostream>
> #include <algorithm>
> #include <vector>
> #include <string>
> #include <ctime>
>
> using namespace std;
>
> vector<string> vs;
>
> FILE *fp=fopen("D:\\v.txt","r");
>
> int main() {
>    int i=0;
>    while (true) {
>        char line[50];
>        if (!fgets(line,50,fp)) break;
>        vs.push_back(line);
>        ++i;
>    }
>    fclose(fp);
>
>    double t;
>    t=clock()/CLOCKS_PER_SEC;
>      sort(vs.begin(),vs.end());
>    cout << clock()/CLOCKS_PER_SEC << endl;
>
>    int m;
>    cin >> m;
>    cout << vs[m];
>    getchar();
> return 0;
> }
>
> --
> http://mail.python.org/mailman/listinfo/python-list
> 




More information about the Python-list mailing list