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

2008-05-23 Thread Lie
On Apr 30, 8:57 pm, n00m <[EMAIL PROTECTED]> wrote: > >>> a = ['zzz', 'aaa'] > >>> id(a[0]), id(a[1]) > > (12258848, 12259296)>>> a.sort() > >>> id(a[0]), id(a[1]) > > (12259296, 12258848) > > That proves you know nothing, that is a list operation, not a string operation. -- http://mail.python.org

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

2008-04-30 Thread n00m
>>> a = ['zzz', 'aaa'] >>> id(a[0]), id(a[1]) (12258848, 12259296) >>> a.sort() >>> id(a[0]), id(a[1]) (12259296, 12258848) >>> -- http://mail.python.org/mailman/listinfo/python-list

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

2008-04-29 Thread Lie
On Apr 28, 2:14 am, n00m <[EMAIL PROTECTED]> wrote: > Lie wrote: > > On Apr 27, 6:28�am, n00m <[EMAIL PROTECTED]> wrote: > > > No so simple, guys. > > > E.g., I can't solve (in Python) this:http://www.spoj.pl/problems/INTEST/ > > > Keep getting TLE (time limit exceeded). Any ideas? After all, it's

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

2008-04-27 Thread hdante
On Apr 27, 4:54 pm, n00m <[EMAIL PROTECTED]> wrote: > Another PC, another OS (Linux) and another compiler C++ (g++ 4.0.0-8) > > Compare 2 my latest submissions:http://www.spoj.pl/status/SBANK,zzz/ > > times: 1.32s and 0.60s > > Submitted codes: > > import sys > z=sys.stdin.readlines() > print z[5]

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

2008-04-27 Thread n00m
Another PC, another OS (Linux) and another compiler C++ (g++ 4.0.0-8) Compare 2 my latest submissions: http://www.spoj.pl/status/SBANK,zzz/ times: 1.32s and 0.60s Submitted codes: import sys z=sys.stdin.readlines() print z[5] #include #include #include #include using namespace std; vect

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

2008-04-27 Thread n00m
Lie wrote: > On Apr 27, 6:28�am, n00m <[EMAIL PROTECTED]> wrote: > > No so simple, guys. > > E.g., I can't solve (in Python) this:http://www.spoj.pl/problems/INTEST/ > > Keep getting TLE (time limit exceeded). Any ideas? After all, it's > > weekend. > > > > 450. Enormous Input Test > > Problem co

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

2008-04-27 Thread Lie
On Apr 27, 6:28 am, n00m <[EMAIL PROTECTED]> wrote: > No so simple, guys. > E.g., I can't solve (in Python) this:http://www.spoj.pl/problems/INTEST/ > Keep getting TLE (time limit exceeded). Any ideas? After all, it's > weekend. > > 450. Enormous Input Test > Problem code: INTEST > > The purpose of

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

2008-04-27 Thread n00m
Both codes by Dennis Lee Bieber are Ok. The 2nd one ("slurper") , seems , a bit faster. I only corrected the author's typo: should be "% div" instead of "/ div". And added this (don't know helped it or not): if div == 1: print lim return And of course: import psyco psyco.full() -- http:

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

2008-04-27 Thread Gabriel Ibanez
Message - From: "n00m" <[EMAIL PROTECTED]> Newsgroups: comp.lang.python To: 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). Incredible. Python

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

2008-04-27 Thread SL
Have you tried this now? First try again with pure C code and compile with a C compiler, not with C++ code and C++ compiler. Then, tweak the code to use more buffering, to make it more similar to readline code, like this (not tested): #include #include char vs[1002000][100]; char buffer

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

2008-04-26 Thread n00m
Oops... I spotted a slip in my C++ code. Forgot " - t" in cout << clock()/CLOCKS_PER_SEC << endl; The correct proportion is 7.5s / 2.75s = 2.7 times. -- http://mail.python.org/mailman/listinfo/python-list

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

2008-04-26 Thread n00m
One more brick. This time I compare list.sort() vs sort(vector). 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 #include #incl

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

2008-04-26 Thread n00m
Dennis Lee Bieber wrote: > (untested for both): > -=-=-=-=-=-=- Many thanks but alas both your codes got "wrong answer" verdict. I can't understand why; they seem Ok (but I'm a bit sleepy:)). -- http://mail.python.org/mailman/listinfo/python-list

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

2008-04-26 Thread Christian Heimes
SL schrieb: > 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 :) Of course it is. Checkout the Python sources :) Christian -- http://mail.python.org/mailman

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

2008-04-26 Thread n00m
Btw seems all accepted pyth solutions (for this prob) used Psyco. -- http://mail.python.org/mailman/listinfo/python-list

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

2008-04-26 Thread n00m
I'm there since summer 2004 :) (with several time breaks) -- http://mail.python.org/mailman/listinfo/python-list

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

2008-04-26 Thread hdante
On Apr 26, 8:28 pm, n00m <[EMAIL PROTECTED]> wrote: > No so simple, guys. > E.g., I can't solve (in Python) this:http://www.spoj.pl/problems/INTEST/ > Keep getting TLE (time limit exceeded). Any ideas? After all, it's > weekend. > > 450. Enormous Input Test > Problem code: INTEST > > The purpose of

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

2008-04-26 Thread n00m
No so simple, guys. E.g., I can't solve (in Python) this: http://www.spoj.pl/problems/INTEST/ Keep getting TLE (time limit exceeded). Any ideas? After all, it's weekend. 450. Enormous Input Test Problem code: INTEST The purpose of this problem is to verify whether the method you are using to rea

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

2008-04-26 Thread hdante
On Apr 26, 5:54 pm, n00m <[EMAIL PROTECTED]> wrote: > hdante: > > I run your code quite a few times. > Its time = 0.734s. > Of mine = 0.703-0.718s. > > PS All I have is an ancient Mingw compiler (~1.9.5v) in Dev-C++. Okay, now I believe in you. :-P The next step would be to reimplement readline.

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

2008-04-26 Thread Carl Banks
On Apr 26, 12:15 pm, n00m <[EMAIL PROTECTED]> wrote: > fgets() from C++ iostream library??? Sheesh. That'll teach me to read carefully. (Ok, it probably won't.) Other two points still apply. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

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

2008-04-26 Thread n00m
hdante: I run your code quite a few times. Its time = 0.734s. Of mine = 0.703-0.718s. PS All I have is an ancient Mingw compiler (~1.9.5v) in Dev-C++. -- http://mail.python.org/mailman/listinfo/python-list

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

2008-04-26 Thread n00m
>> char vs[1002000][99]; In the file 1001622(or so) records like phone number + f/l names. So the reserving makes sense, i think. Populating of vector is by zillion times slower. >> Is there an implementation of f.readlines on the internet somewhere? I was greatly surprised how fast it is. As a

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

2008-04-26 Thread hdante
On Apr 26, 1:15 pm, n00m <[EMAIL PROTECTED]> wrote: > fgets() from C++ iostream library??? > fgets is part of the standard C++ library and it lives in the std namespace. > I guess if I'd came up with "Python reads SLOWER than C" > I'd get another (not less) smart explanation "why it's so". -- ht

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

2008-04-26 Thread hdante
On Apr 26, 12:10 pm, n00m <[EMAIL PROTECTED]> wrote: > Both codes below read the same huge(~35MB) text file. > In the file > 100 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.t

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

2008-04-26 Thread SL
"SL" <[EMAIL PROTECTED]> schreef in bericht news:[EMAIL PROTECTED] "n00m" <[EMAIL PROTECTED]> schreef in bericht news:[EMAIL PROTECTED] using namespace std; char vs[1002000][99]; if (!fgets(vs[i],999,fp)) break; BTW why are you declaring the array as 99 and pass 999 to fgets to r

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

2008-04-26 Thread SL
"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 #include #include #include using namespace std; char vs[1002000][99]; FILE *f

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

2008-04-26 Thread n00m
fgets() from C++ iostream library??? I guess if I'd came up with "Python reads SLOWER than C" I'd get another (not less) smart explanation "why it's so". -- http://mail.python.org/mailman/listinfo/python-list

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

2008-04-26 Thread Carl Banks
On Apr 26, 11:10 am, n00m <[EMAIL PROTECTED]> wrote: > Both codes below read the same huge(~35MB) text file. > In the file > 100 lines, the length of each line < 99 chars. > > Stable result: > Python runs ~0.65s > C : ~0.70s > > Any thoughts? Yes. Most of the dirty work in the Python example

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

2008-04-26 Thread n00m
Both codes below read the same huge(~35MB) text file. In the file > 100 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=inp