[PyQt] Observations with nesting-level: Performance of QTreeView

Baz Walter bazwal at ftml.net
Sun Oct 10 22:28:15 BST 2010


On 10/10/10 18:39, Knacktus wrote:
> Those results are very interesting! Thanks.
> Just to confirm: You had 5000 items and to expand the whole tree took
> only 0.67 seconds? Also, only 1 call to parent().
> Now, that makes my wonder and hope. The main differences are that I'm on
> Windows 7 and I'm using pyqt 4.7.4 (build on Qt 4.6 afaik). I've read
> about some performance optimisation in Qt 4.7. That would be great news.

yes, 5000 in 0.67 for qt 4.7 is correct. the only change to your 
previous example code was to replace the expand_all method with this:

     def expand_all(self):
         from cProfile import runctx
         runctx('self.expandAll()', globals(), locals())

but as you will see below, running the same code with qt 4.6 is hugely 
less efficient:

[mandriva-linux 2.6.33, python 2.6.5, qt 4.6.2, sip 4.11.1, pyqt 4.7.7]

87652609 function calls in 424.383 CPU seconds

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.000    0.000  424.383  424.383 <string>:1(<module>)
15004    0.141    0.000    0.462    0.000 tree_model.py:178(rowCount)
10001    0.048    0.000    0.066    0.000 tree_model.py:190(columnCount)
    24    0.000    0.000    0.000    0.000 tree_model.py:193(data)
    12    0.000    0.000    0.000    0.000 tree_model.py:206(headerData)
  5005    0.046    0.000    0.127    0.000 tree_model.py:213(index)
12502501  141.847    0.000  368.758    0.000 tree_model.py:218(parent)
12522513   74.889    0.000  125.745    0.000 tree_model.py:233(
                                             view_item_from_index)
  4999    0.021    0.000    0.021    0.000 tree_model.py:43(__init__)
12517509   26.839    0.000   26.900    0.000 tree_model.py:50(children)
  5000    0.039    0.000    0.061    0.000 tree_model.py:77(
                                             get_view_item_children)
     3    0.000    0.000    0.000    0.000 {built-in method column}
12502505   46.578    0.000   46.578    0.000 {built-in method
                                                 createIndex}
     1   54.969   54.969  424.383  424.383 {built-in method expandAll}
12522506   24.006    0.000   24.006    0.000 {built-in method
                                                 internalPointer}
12522513   26.850    0.000   26.850    0.000 {built-in method isValid}
     3    0.000    0.000    0.000    0.000 {getattr}
25008    0.048    0.000    0.048    0.000 {len}
     1    0.000    0.000    0.000    0.000 {method 'disable' of
                                             '_lsprof.Profiler' objects}
12497500   28.062    0.000   28.062    0.000 {method 'index' of
                                                 'list' objects}




More information about the PyQt mailing list