1 / 28
Sep 2009

On Sep 14th 2009 the python interpreter was updated to version 2.6 and the psyco module is no longer supported.
So there are lots of problemsets that python programmers are no longer able to solve at all because of large I/O and/or strict time limit. A dark day for python programmers at SPOJ ... confused

It is not only psyco that worries me. It is the performance of 2.6 in general which is really bad compared to the previous release.
I have verified
- CLTZ: 13% worse than before
- STAMPS: 78% worse than before (uploaded two times because I couldnt believe it, but it is the sad truth)

I find that absolutely emberassing and disappointing for Python. frowning

But...

Still there are new records possible. See CPRMT. smile

8 days later

Psyco is back again!

Today I was able to submit python solutions (python 2.6) using psyco!
Thanks a lot to the admins!

... but the benefit is still poor compared to the previous 2.5.

NSTEPS PY2.5 - NO PSYCO: 0.28
NSTEPS PY2.5 - PSYCO: 0.18
NSTEPS PY2.6 - NO PSYCO: 0.50
NSTEPS PY2.6 - PSYCO: 0.37

Conclusion: With Psyco in 2.6 we dont event get the same performance as py-2.5 without psyco.Still catastrophic performance of Py-2.6. And a lot of problems cant even be solved with psyco now.

Seems at least partially right.

My solutions:
nsteps with py 2.5 and psyco: 0.13 s
nsteps with py 2.5 and psyco: 0.16 s

So, I think one has to do some experimenting and checking what kind of operations CAN be processed really faster with py2.6+psyco and which cannot. As I see it, it is especially the input (and conversion from str to int) that are much slower now than with python 2.5.
Example https://www.spoj.pl/problems/INTEST/:
python 2.5 with psyco: 7.73 s
python 2.6 with psyco: 10.69 s

... you obviously found a brilliant solution for that problem. Perhaps I come back to that problem to think of what can be done here to speed it up.
The direct comparisson 2.5, 2,6 of my solution without code changes still looks very bad.

Well I redid my little experiment with my [color=#FF0000]48 python solutions[/color] and got this now:

Python 2.5 + psyco: [color=#FF0000]48 AC + 0 TLE[/color]
Python 2.6: [color=#FF0000]19 AC + 28 TLE[/color]
Python 2.6 + pysco: [color=#FF0000]28 AC + 20 TLE[/color]

This shows to me that in general python 2.6 has worse performance. Psyco helps a little bit, but the overall performance is still a problem. We are going to suffer (even more) to make python solutions ACceptable.

You can check the list of executions here: br.spoj.pl/status/diegocaminha/signedlist/1

  • I wonder if the designers of python language care at all about performance frowning

As I see it, it isn't much worse than before. There were and are several problems that are impossible to solve using python, some of them because of the very strict time limit (e.g. https://www.spoj.pl/problems/ETF/1) and some others because of the enormous input. But there still remain a lot of problemsets you can use with python.

In some cases one should just improve the algorithm: https://br.spoj.pl/ranks/FATORIAL/lang=PYTH

I have more than 200 python2.5 solutions AC and there should be only a few that I won't get AC, e.g. https://www.spoj.pl/problems/SUMITR/ and https://www.spoj.pl/problems/ODDDIV/, both of which needed a lot (!) of optimizations to get it AC within the time limit using python.

Sure. The numbers I gave are just for having some general idea of the impact in the version update. Some of the solutions can get AC by optimizing the algorithm (when I see an easy time constraint problem, I usually prefer a clean/easy/'fast enough' solution), but my personal impression is still many (extra) problems would not get acceptable. But it is just my (non-expert) point of view.

Just some facts:

CLTZ:
2.5 .... 2.62
2.6.1 .... 2.97
2.6.2 .... 3.92

STAMPS:
2.5 .... 0.64
2.6.1 .... 1.14
2.6.2 .... 1.54

I dont think the Python developers have made their homework. They should do some exercises on SPOJ instead. Soon we get TLE on TEST. imp
Can we resume to 2.5?

Just some other facts (= my solutions for STAMPS):
Python 2.5 ... 0.62 s
Python 2.6 ... 0.68 s

Excellent of course. No doubt. The question is: Have you changed the code meanwhile? I havent. I just submitted the code as is. If you want to compare something you have to keep something constant.
Submit your CLTZ solution.

CLTZ:
Python 2.5.x .... 1.26 s (0.81 with psyco)
Python 2.6.2 .... 2.31 s (1.68 s with psyco)

It is as I said before: There are some problemsets where you can optimize your code so that there is only little loss of performance, there are others (like CLTZ), where you can't. But nevertheless: You can get your solution to CLTZ get AC, even with Python 2.6.2 and without psyco. It isn't as fast as before, but - "what shalls" (as we Germans like to say ... )

9 days later

Then improve your algorithm ... smile
(My solution run in 3.65 s with python 2.5 and runs is 4.23 s with python 2.6.2.)

What algorithm? smile In my code only a dozen of lines. Nothing to improve.

PS
I vote for switching back to Python 2.5 smile

If the time limit is 7 s and there are python solutions AC in < 5 s and your solution gives TLE: There IS something to improve!

If the time limit is 7 s and there are python solutions AC in < 5 s and your solution gives TLE: There IS something to improve!

I have in store my ACcepted C++ code smile

PS
Adding Sevens: spoj.pl/ranks/ANARC08B/lang=PYTH
All of this summer submissions (i.e. v.2.5). Today my py code gets only TLEs (I've never solved this prob before).

Then improve your algorithm ... wink
I submitted my old solution today (python 2.6.2) and got AC in 0.80 s with pure python and 0.30 s with psyco.

What can be improved in my TLE code?

import psyco
psyco.full()
def foo():
    a = (\
        '063',
        '010',
        '093',
        '079',
        '106',
        '103',
        '119',
        '011',
        '127',
        '107')
    b = {\
    '063':'0',
    '010':'1',
    '093':'2',
    '079':'3',
    '106':'4',
    '103':'5',
    '119':'6',
    '011':'7',
    '127':'8',
    '107':'9'}

import sys
w = sys.stdin.readlines()

for wi in w:
    s = wi.strip()
    if s == 'BYE':
        return
    p = s[:s.index('+')]
    q = s[s.index('+') + 1:][:-1]
    pp = ''
    for i in range(0, len(p), 3):
        pp += b[p[i:i + 3]]
    qq = ''
    for i in range(0, len(q), 3):
        qq += b[q[i:i + 3]]
    z = str(int(pp) + int(qq))
    r = ''
    for zi in z:
        r += a[int(zi)]
    print s + r
foo()