11 / 28
Sep 2009

... 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()

Testdata is available (see link in the bottom of problem description), so find the bottleneck by doing some profiling. Then you'll find out yourself.

alas... my dial-up connection is too slow for downloading anything with size more than 1-2MB

You don't need official testdata to find the bottleneck(s). Just create your own testdata.

4 years later

Forum jest po to aby odpowiadać na pytania? Niestety, "ale nie mam innego pomysłu" to nie pytanie wink , mimo to jeszcze raz "powiem":
Jest algoliga.pl1 a tam z lewego boku, taki mały, podobny do tego tu na spoju, niebieski napis [color=#4000BF][b]forum[/b][/color]. "Idąc" tam warto wcześniej odblokować w swojej przeglądarce wykonywanie skryptów.

PS
W zasadzie wystarczyłoby tylko zwrócić uwagę na pierwszy link w moim podpisie.

11 months later