Search code examples
apache-flexflex-spark

How to test how performant an item renderer is?


I have just watched this video on Performance Tips and Tricks for Flex and Flash Development and it lists 3 things that are measured when using and creating Flex.

  • Creation
  • Validation
  • Rendering

How do I measure these items on my own projects? In my case and more specifically for this question, how do I test how long it takes to create my item renderer, validate it and render it?

Is the total of all these events the total time I should use when testing the performance of the item renderer? I mean once it's created then what matters is just the rendering and validation correct?

What I mean is if I have an item renderer I THINK I could find out the creation time by using the following code:

 <itemrenderer initialize="trace('initialized at='+getTimer())" creationComplete="trace('created at='+getTimer())" />

Not sure if this is right. But what about validation and rendering?


Solution

  • Here's what I've got so far:

    timeLabel.text += "\nAbstractDataGridItemRenderer: " + testGridItemRenderer(AbstractDataGridItemRenderer, data, 50);
    

    And the function:

            public function testItemRenderer(renderer:Class, data:Object, iterations:int = 1000, resetTime:Boolean = false):int {
                var layoutManager:LayoutManager = LayoutManager.getInstance();
                var time:int = getTimer();
                var itemRenderer:IItemRenderer;
    
                for (var i:int;i<iterations;i++) {
                    itemRenderer = new renderer();
                    itemRenderer.data = data.name + i;
                    itemRenderer.width = 300;
                    itemRenderer.height = 30;
                    itemRenderer.y = i * 30;
                    itemRenderer.label = LabelUtil.itemToLabel(data, "label");
                    addElement(itemRenderer);
                    //trace("initialized = " + ILayoutManagerClient(itemRenderer).initialized);
                    layoutManager.validateClient(ILayoutManagerClient(itemRenderer), false);
                    //trace("initialized = " + ILayoutManagerClient(itemRenderer).initialized);
                }
    
                if (resetTime) {
                    time = getTimer();
                    for (i=0;i<iterations;i++) {
                        itemRenderer.data = data.name + i;
                        itemRenderer.label = LabelUtil.itemToLabel(data, "label");
                        //addElement(itemRenderer);
                        //trace("initialized = " + ILayoutManagerClient(itemRenderer).initialized);
                        layoutManager.validateClient(ILayoutManagerClient(itemRenderer), false);
                        //trace("initialized = " + ILayoutManagerClient(itemRenderer).initialized);
                    }
                    return getTimer() - time;
                }
    
                return getTimer() - time;
            }
    

    I don't know if this is right but it's giving me some numbers to work with. I'd rather not add it to the stage but it seems I have to do that to get it to initialize.

    Initialized is true when an object has been through all three phases of layout: commitment, measurement, and layout.

    Update. I added a reset phase. This leaves the rendering phase.