[PyKDE] Custom sorting function for the QListView widget

Detlev Offenbach detlev at die-offenbachs.de
Sun Jul 4 12:14:01 BST 2004


Hi,

> Hi,
>
> I've tried your suggestion and it does indeed seem to show an increase
> in performance. I've measured it as being around 10% of improvement
> for a large dataset (10000 records on the listview). My datasets will
> probabibly be around 1000 records, and at that level the difference
> doesn't seem very noticeable. It takes around 4 seconds on my machine
> to sort the list, and even though it may sound a little bit too
> demanding from me but I think I will probably have a much better
> result by implementing it directly on C++. I was betting on Python for
> the simplicity, but I believe I really hit a soft spot this time.
>
> Do you know how Python delivers its functions to the C++ interface? I
> mean in this case, would it be justifiable to believe most of the
> performance hit comes from the fact that the C++ QListView sorting
> routine has to call a function that is being run on the Python virtual
> machine a number O(n * log n ) times? Would this incur in a boundry
> cross? If this is the case, I am pretty confident that the solution
> should be heading for C++ in this one.
>
> Thanks for all your help Troy.
> Fernando
>

Before you go through all the hassles implementing a C++ extension you 
could try to preformat your numerical data (e.g. left padding with 
blanks) when you create the QListViewItems and later on rely on the 
native sort functions.

Exchange the lines

for i in range(1000):
    item = MyQListViewItem(lst, "%s" % i)

of your example with

for i in range(1000):
    item = QListViewItem(lst, "%4d" % i)

Detlev
-- 
Detlev Offenbach
detlev at die-offenbachs.de




More information about the PyQt mailing list