r3 - 24 Aug 2004 - 00:09:15 - HeikkiToivonenYou are here: OSAF >  Projects Web  >  DevelopmentHome > PerformanceProject > ItemPerformance
I did a simple comparison of time it takes to recursively iterate through all the blocks, which are Items, compared to how long it takes to iterate through all the wxWidgets that correspond to each block. The code involved is nearly identical, except in one case it accesses Item attributes, and in the other it access wxPython attributes and/or methods.

First the routine that is Item based:

        def broadcast (block, methodName, notification, stopAtEventBoundary = True):
            """
              Call method named methodName on every block and it's children
            who implements it, except for the block that posted the event,
            to avoid recursive calls.
            """
            if block != notification.data['sender']:
                callMethod (block, methodName, notification)
            for child in block.childrenBlocks:
                if child is not None and child.isShown and not (stopAtEventBoundary and child.eventBoundary):
                    broadcast (child, methodName, notification, stopAtEventBoundary)

it's wxWidget counterpart:

            def broadcastTest (widget, methodName, notification, stopAtEventBoundary = True):
                """
                  Call method named methodName on every block and it's children
                who implements it, except for the block that posted the event,
                to avoid recursive calls.
                """
                if widget != notification.data['sender']:
                    print widget
                    callMethod (widget, methodName, notification)
                for child in widget.GetChildren():
                    if child is not None and child.IsShown() and not (stopAtEventBoundary and child.IsRetained()):
                        broadcastTest (child, methodName, notification, stopAtEventBoundary)

Each routine refers to:

        def callMethod (block, methodName, notification):
            """
              Call method named methodName on block
            """
            try:
                member = getattr (block, methodName)
            except AttributeError:
                return False
            member (notification)
            return True

Running Chandler release outside the debugger I was able to visit 24,427 wxPython objects/second and only 2623 Items/second. Modifying getattr in callMethod to avoid calling the repository as follows:

        def callMethod (block, methodName, notification):
            """
              Call method named methodName on block
            """
            try:
                member = getattr (type(block), methodName)
            except AttributeError:
                return False
            member (block, notification)
            return True

improves the results to 16,209 objects/second. Note, that the call to member must be modified as well.

-- JohnAnderson - 23 Aug 2004

Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r3 < r2 < r1 | More topic actions
 
Open Source Applications Foundation
Except where otherwise noted, this site and its content are licensed by OSAF under an Creative Commons License, Attribution Only 3.0.
See list of page contributors for attributions.