1 Reply Latest reply on Oct 26, 2008 9:49 AM by matthewlee

    Capturing Render Times



      I'm trying to measure the time it takes to render things like circles, rectangles, text, images, ect. Here is a snippet of code that creates random circles and adds them to a UIComponent.

      var result:UIComponent = new UIComponent();
      addChild(result);
      // render time
      var rdiff:Number = new Number();
      // execution time
      var ediff:Number = new Number();
      var circle:Sprite = new Sprite();
      // counter
      var i:int = 0;
      // time place holders
      var before:Number = new Number();
      var after:Number = new Number();

      while(i < rows) {
      // Create x many random circles
      before = new Date().time;
      circle.graphics.beginFill(Math.random() * 0xFFFFFF,1);
      var rnd:int = Math.round(Math.random() * (300)) + 0;
      var rnd2:int = Math.round(Math.random() * (300)) + 0;
      circle.graphics.drawCircle(rnd,rnd2,50);
      circle.graphics.endFill();
      after = new Date().time;
      ediff += (after - before);
      // Display x many circles
      before = new Date().time;
      result.addChild(circle);
      after = new Date().time;
      rdiff = rdiff + (after - before);
      i = i + 1;

      }

      Would this be the correct way of measuring the render time? Am i way off or silly?
        • 1. Re: Capturing Render Times
          Level 1
          So I have been measuring the render time as the time it takes to go through addChild(). Here is what I found about how addChild() works. Which of these would or would not be related to the render time?

          1. Container.addChild(b);

          Flex performs the following actions:

          a. Sets the parent property for the component to reference its parent
          container.

          b. Computes the style settings for the component.

          c. Dispatches the preinitialize event on the component.

          d. Calls the component’s createChildren() method.

          e. Calls the invalidateProperties(), invalidateSize(), and
          invalidateDisplayList() methods to trigger later calls to the
          commitProperties(), measure(), or updateDisplayList() methods during the
          next render event.

          The only exception to this rule is that Flex does not call the measure()
          method when the user sets the height and width of the component.

          f. Dispatches the initialize event on the component. At this time, all of
          the component’s children are initialized, but the component was not sized
          or processed for layout. You can use this event to perform additional
          processing of the component before it is laid out.

          g. Dispatches the childAdd event on the parent container.

          h. Dispatches the initialize event on the parent container.

          2. During the next render event, Flex performs the following actions:

          a. Calls the component’s commitProperties() method.

          b. Calls the component’s measure() method.

          c. Calls the component’s layoutChrome() method.

          d. Calls the component’s updateDisplayList() method.

          e. Dispatches the updateComplete event on the component.

          3. Flex dispatches additional render events if the commitProperties(),
          measure(), or updateDisplayList() methods call the invalidateProperties(),
          invalidateSize(), or invalidateDisplayList() methods.

          4. After the last render event occurs, Flex performs the following actions:

          a. Makes the component visible by setting the visible property to true.

          b. Dispatches the creationComplete event on the component. The component
          is sized and processed for layout. This event is only dispatched once when
          the component is created.

          c. Dispatches the updateComplete event on the component. Flex dispatches
          additional updateComplete events whenever the layout, position, size, or
          other visual characteristic of the component changes and the component is
          updated for display.

          Most of the work for configuring a component occurs when you add the
          component to a container by using the addChild() method. That is because
          until you add the component to a container, Flex cannot determine its
          size, set inheriting style properties, or draw it on the screen.