Tkinter displaying 300 records sluggish
Anand B Pillai
abpillai at lycos.com
Tue Mar 11 02:04:59 EST 2003
Hi
Probably this is out of context. But you should strongly
consider using wxPython for these kind of tasks. Speed is not
a virtue of tkinter. I am not familiar with tkinter though I
can tell you that wxPython would be surely faster than tkinter
for most performance intensive apps.
Regards
Anand B Pillai
www.members.fortunecity.com/anandpillai
ibarg at as.arizona.edu (Irene Barg) wrote in message news:<ad94e30f.0303100953.12337787 at posting.google.com>...
> Eric,
>
> First, my apologies for this long post. The module code was 30K, too
> long to post, hence the code snippet. The function 'lineheight' gives
> me the largest element in a row so that I can size the text widget.
>
> def lineheight(self,maxw,data):
> numchar = []
> for val in data:
> if val: numchar.append(len(val))
> biggest = max(numchar) #return the largest element in row
> h = (biggest / maxw) + 1
> return h
>
> I ran profile, and below are some statistics below. Note, the 2nd set
> of statistics sorting on 'time', shows that the code is spending
> 8.97sec
> inside the 'displayColumns' function, the code snippet in my original
> post. I just re-check 'displayColumns' function it just uses
> Tkinter, no PMW calls. BTW, I re-ran the code through profiler
> with the call to 'lineheight' commented out, the times were actually
> slightly higher. On the Sun system, I am still running Python 2.1.1,
> so I placed the following line at the very top of the main program:
>
> from __future__ import nested_scopes #I am still using 2.1
>
> In summary (output from profiler follows), it takes 1/2 the time
> to load 300 records on the P4 under Linux, vs Sun Ultra under
> Solaris. The reporting of the statistics appears different
> between Solaris and Linux (see details below). Your comments
> are greatly appreciated!
>
> Sun Ultra 60 2x360MHz, 256MBytes RAM (earlier posted wrong RAM):
> Python 2.1.1 (#1, Aug 7 2001, 14:18:53) [C] on sunos5
> Type "copyright", "credits" or "license" for more information.
> IDLE 0.8 -- press F1 for help
> >>> import pstats
> >>> p=pstats.Stats('pubdbprof')
> >>> p.sort_stats('cumulative').print_stats(10)
> Mon Mar 10 09:07:13 2003 pubdbprof
>
> 74980 function calls (67621 primitive calls) in 14.150 CPU
> seconds
>
> Ordered by: cumulative time
> List reduced from 359 to 10 due to restriction <10>
>
> ncalls tottime percall cumtime percall
> filename:lineno(function)
> 377/1 0.000 0.000 14.150 14.150 <string>:1(?)
> 1 0.000 0.000 14.150 14.150 profile:0(doit())
> 1 0.000 0.000 14.150 14.150 pubdbmain.py:751(doit)
> 16/5 0.010 0.001 13.920 2.784
> /home/barg/local/lib/python2.1/site-packages/Pmw/Pmw_0_8_5/lib/PmwLoader.py:132(__getattr__)
> 16/5 0.030 0.002 13.900 2.780
> /home/barg/local/lib/python2.1/site-packages/Pmw/Pmw_0_8_5/lib/PmwLoader.py:70(_getmodule)
> 1 0.000 0.000 13.640 13.640
> pubdbmain.py:187(__init__)
> 1 0.190 0.190 12.190 12.190
> /home/barg/local/lib/python2.1/lib-tk/Tkinter.py:928(mainloop)
> 57/47 0.010 0.000 12.040 0.256
> /home/barg/local/lib/python2.1/site-packages/Pmw/Pmw_0_8_5/lib/PmwBase.py:1666(__call__)
> 1 0.000 0.000 11.320 11.320
> ./dbutils/dbtools.py:177(searchDb)
> 1 0.070 0.070 11.320 11.320
> ./dbutils/flatdb.py:145(getRowsWithValue)
>
> >>> p.sort_stats('time').print_stats(10)
> Mon Mar 10 09:07:13 2003 pubdbprof
>
> 74980 function calls (67621 primitive calls) in 14.150 CPU
> seconds
>
> Ordered by: internal time
> List reduced from 359 to 10 due to restriction <10>
>
> ncalls tottime percall cumtime percall
> filename:lineno(function)
> 11866 1.800 0.000 2.650 0.000
> /home/barg/local/lib/python2.1/lib-tk/Tkinter.py:953(_options)
> 2789 1.700 0.001 3.020 0.001
> /home/barg/local/lib/python2.1/lib-tk/Tkinter.py:1744(__init__)
> 17831 1.270 0.000 1.270 0.000
> /home/barg/local/lib/python2.1/lib-tk/Tkinter.py:72(_cnfmerge)
> 1 1.240 1.240 8.970 8.970
> ./dbforms.py:237(displayColumns)
> 2789/40 1.050 0.000 1.530 0.038
> /home/barg/local/lib/python2.1/lib-tk/Tkinter.py:1760(destroy)
> 2675 0.890 0.000 1.570 0.001
> /home/barg/local/lib/python2.1/lib-tk/Tkinter.py:1663(grid_configure)
> 3191 0.750 0.000 1.520 0.000
> /home/barg/local/lib/python2.1/lib-tk/Tkinter.py:1063(configure)
> 3120 0.550 0.000 1.220 0.000
> /home/barg/local/lib/python2.1/lib-tk/Tkinter.py:1152(_grid_configure)
> 4 0.390 0.098 0.410 0.102
> /home/barg/local/lib/python2.1/site-packages/Pmw/Pmw_0_8_5/lib/PmwBase.py:143(forwardmethods)
> 2829/48 0.380 0.000 1.540 0.032
> /home/barg/local/lib/python2.1/site-packages/Pmw/Pmw_0_8_5/lib/PmwBase.py:1644(__TkinterWidgetDestroy)
>
> Pentium 4, 1.70GHz CPU, 260MB RAM:
> Python 2.2.2 (#1, Jan 7 2003, 15:12:31)
> [GCC 3.2 20020903 (Red Hat Linux 8.0 3.2-7)] on linux2
> Type "copyright", "credits" or "license" for more information.
> IDLE 0.8 -- press F1 for help
> >>> import pstats
> >>> p=pstats.Stats('pubdbprof')
> >>> p.sort_stats('cumulative').print_stats(10)
> Mon Mar 10 10:22:32 2003 pubdbprof
>
> 80116 function calls (73986 primitive calls) in 7.780 CPU
> seconds
>
> Ordered by: cumulative time
> List reduced from 366 to 10 due to restriction <10>
>
> ncalls tottime percall cumtime percall
> filename:lineno(function)
> 1 0.000 0.000 7.780 7.780 profile:0(doit())
> 377/1 0.010 0.000 7.780 7.780 <string>:1(?)
> 1 0.000 0.000 7.770 7.770 pubdbmain.py:751(doit)
> 1 0.430 0.430 6.980 6.980
> //usr/lib/python2.2/lib-tk/Tkinter.py:935(mainloop)
> 214/205 0.000 0.000 6.550 0.032
> /usr/lib/python2.2/site-packages/Pmw/Pmw_1_1/lib/PmwBase.py:1710(__call__)
> 1 0.000 0.000 3.250 3.250 pubdbmain.py:683(search)
> 1 0.000 0.000 3.250 3.250
> pubdbmain.py:687(dosearch)
> 1 0.000 0.000 3.100 3.100
> pubdbmain.py:709(showresults)
> 1 0.320 0.320 3.070 3.070
> dbforms.py:237(displayColumns)
> 65/17 0.000 0.000 2.000 0.118
> /usr/lib/python2.2/site-packages/Pmw/Pmw_1_1/lib/PmwBase.py:373(destroy)
>
>
> <pstats.Stats instance at 0x8328a3c>
> >>> p.sort_stats('time').print_stats(10)
> Mon Mar 10 10:22:32 2003 pubdbprof
>
> 80116 function calls (73986 primitive calls) in 7.780 CPU
> seconds
>
> Ordered by: internal time
> List reduced from 366 to 10 due to restriction <10>
>
> ncalls tottime percall cumtime percall
> filename:lineno(function)
> 2816/45 1.790 0.001 1.990 0.044
> //usr/lib/python2.2/lib-tk/Tkinter.py:1768(destroy)
> 44/37 0.970 0.022 0.970 0.026
> //usr/lib/python2.2/lib-tk/Tkinter.py:832(update_idletasks)
> 2687 0.730 0.000 0.970 0.000
> //usr/lib/python2.2/lib-tk/Tkinter.py:1678(grid_configure)
> 12213 0.520 0.000 0.720 0.000
> //usr/lib/python2.2/lib-tk/Tkinter.py:960(_options)
> 2816 0.490 0.000 0.870 0.000
> //usr/lib/python2.2/lib-tk/Tkinter.py:1752(__init__)
> 1 0.430 0.430 6.980 6.980
> //usr/lib/python2.2/lib-tk/Tkinter.py:935(mainloop)
> 1 0.320 0.320 3.070 3.070
> dbforms.py:237(displayColumns)
> 3400 0.300 0.000 0.480 0.000
> //usr/lib/python2.2/lib-tk/Tkinter.py:1071(configure)
> 18411 0.300 0.000 0.300 0.000
> //usr/lib/python2.2/lib-tk/Tkinter.py:72(_cnfmerge)
> 16/13 0.240 0.015 0.380 0.029
> /usr/lib/python2.2/site-packages/Pmw/Pmw_1_1/lib/PmwLoader.py:70(_getmodule)
>
> Eric Brunel <eric.brunel at pragmadev.com> wrote in message news:<b4hjuv$dt7$1 at news-reader12.wanadoo.fr>...
> > Irene Barg wrote:
> > > Hello All,
> > >
> > > I have a Tkinter/PMW GUI interface to a flatfile (in memory) database
> > > (FlatDB, written by Colin Svingen). When displaying 300 records, it takes approx
> > > 10 seconds on a Sun Ultra 60 2x360MHz, with 1024MBytes RAM running under
> > > Python 2.1, and scrolling through the results is slugish. On a Toshiba Satellite
> > > Pro, Pentium 4, 1.70GHz CPU, 260MB RAM, running RedHat Linux (v8.0)and Pytho2.2,
> > > it takes approx. 5 seconds to display 300 records, but scrolling is much faster.
> > > The result set is a list of lists. The actual size of the db is only 97K, which
> > > shouldn't be a problem with either machine. Are there any coding techniques to
> > > improve performance with Tkinter? Has this been documented anywhere?
> > >
> > > The portion of code that handles the looping through the results follows.
> > > I appreciate your comments. --irene barg
> > [snip code]
> >
> > Looking at your code, I don't see any reason why you get these performances. But
> > since the code is incomplete, it's actually quite hard to tell (e.g., what
> > does the method called "lineheight"?)
> >
> > BTW, did you try to run your code through the profiler? You may discover that
> > Tkinter is not the cause of the problem...
More information about the Python-list
mailing list