Here is part of your profile:
ncalls tottime percall cumtime percall filename:lineno(function)
125112 1.499 0.000 1.499 0.000 {method 'call' of 'tkapp' objects}
125100 1.118 0.000 6.006 0.000 /usr/lib/python3.2/tkinter/__init__.py:2190(_create)
125109 0.942 0.000 1.749 0.000 /usr/lib/python3.2/tkinter/__init__.py:69(_cnfmerge)
125106 0.906 0.000 3.065 0.000 /usr/lib/python3.2/tkinter/__init__.py:1059(_options)
125599 0.851 0.000 0.851 0.000 main.py:10(neighbours)
500433 0.688 0.000 0.688 0.000 {built-in method isinstance}
125100 0.460 0.000 6.787 0.000 main.py:64(draw)
250210 0.341 0.000 0.341 0.000 {method 'update' of 'dict' objects}
125100 0.321 0.000 6.327 0.000 /usr/lib/python3.2/tkinter/__init__.py:2219(create_rectangle)
250205 0.319 0.000 0.319 0.000 {built-in method _flatten}
139 0.255 0.002 8.093 0.058 main.py:63(play)
139 0.181 0.001 1.051 0.008 main.py:19(evolve)
125109 0.134 0.000 0.134 0.000 {method 'items' of 'dict' objects}
125108 0.107 0.000 0.107 0.000 {built-in method callable}
1 0.056 0.056 0.056 0.056 {built-in method create}
Let's extract what is interesting for you here:
cumtime filename:lineno(function)
0.851 main.py:10(neighbours)
6.787 main.py:64(draw)
8.093 main.py:63(play)
1.051 main.py:19(evolve)
You spend most of your time in draw
, contained in the method play
of the class Application.
The lines:
ncalls tottime percall cumtime percall filename:lineno(function)
125100 1.118 0.000 6.006 0.000 /usr/lib/python3.2/tkinter/__init__.py:2190(_create)
125106 0.906 0.000 3.065 0.000 /usr/lib/python3.2/tkinter/__init__.py:1059(_options)
show that your are actually spending your time to create your rectangles.
So if you want to get better performances, just stop instanciating stuff. Just update them! By the way, you'll get far fewer calls to draw
if you use matrices instead of double loops. draw
is slow (6.787 cum. seconds), but remember that you also waste almost 1.5 seconds in these loops.
By the way, evolve
in gol.py
can also be greatly improved by removing these double loops. I think you can make some improvement in the algorithm too.
EDIT:
Oh, and the gol
module contributes to on tenth of the "problem" :)