10 Replies Latest reply on Feb 12, 2009 8:41 AM by rtalton

    Measuring time

      I have developed a simple Flex-Java App using Blaze DS.
      I click a button to populate the datagrid control using Blaze DS.
      I want to measure the time taken for the operation.
      On the Java side, I have already added statements that helps me to measure the no. of seconds to complete Java Service calls. I want to do the same on Flex side.
      How can I do that?
      I am very new to Flex and could not find any class like System in Java that would help me.
        • 1. Re: Measuring time
          rtalton Level 4
          Start a timer when you send for the data (on your button click):
          public function onDataRequest():void{
          //Data request goes here.
          timer = new Timer(1,0); // one ms., infinite repeat
          Upon the data's return, stop the timer and get the currentCount property.
          • 2. Re: Measuring time
            amvit Level 1
            Thank you very much for your answer.In fact I looked at the documentation of Timer yesterday but could not figure out way to use this and hence posted the question.
            I did the same but I have an question about it.
            I am actually invoking a Java service which interacts with Stored proc and returns data back to flex data grid using Blaze DS.
            As per the time measurements in my Java service layer it shows me it took 4 seconds to complete the proc. call. While at the same time I get ~1000(ms?) as current count in flex app from the time the service is called and data is returned and populated into an ArrayCollection in ActionScript.
            My question is how come it can be only 1seconds because Java service itself took ~3-4 seconds to complete.
            Is there something at the way I am looking at the currentCount in Flex?
            Thanks for your kind help.
            • 3. Re: Measuring time
              rtalton Level 4
              Can you post your timer code?
              I set my timer to 1 millisecond: timer = new Timer(1,0);
              ..and since the repeat count is zero, the currentCount property is the same as the number of milliseconds.
              • 4. Re: Measuring time
                amvit Level 1
                Thanks for your reply.
                See the attached code.

                This time is displayed as 1000(ms?) whereas proc alone took ~3 seconds to complete. This the reason I am not sure about the timer timing displayed on Flex app.

                Thanks once again,
                • 5. Re: Measuring time
                  Level 7
                  The reason that this is happening is that the timer in Flex is limited
                  by the framerate. The event will only fire once per frame.

                  I think there might be a static method that will give you the time
                  somewhere, but I can't remember it right now. You can, however, make an
                  instance of Date, and use the time property or the getTime() method.
                  Call it once before, and once after your code runs, and then subtract them.
                  • 6. Re: Measuring time
                    amvit Level 1
                    Thanks a lot for your reply. I think going by the Date way is much better.
                    BTW which book you would recommend for learning Flex. I am an expert in Java and J2EE and now doing some work with flex. But from the paradigm which I am coming from is Struts based so its very difficult to map the user interface in Flex for me.
                    • 7. Measuring time
                      amvit Level 1
                      Hi All,
                      I am very pleased to let you know that I found something using which I can measure the time for the whole operation.
                      It was just the matter of going through Flex documents thoroughly.
                      There is "flash.utils.getTimer" that can be used to get the Start time (int) and then the end time (int) to compute the difference.
                      This was as simple as the code below. It also reflex the correct time (Time taken for execution of Java Service(IBatis Stored Proc execution) + time to render the flex data grid.

                      Thanks very much,
                      • 8. Re: Measuring time
                        rtalton Level 4
                        I didn't bring up the getTimer() function because Adobe does not recommend using it anymore. This quote is from the help docs, under "Controlling time intervals", concerning the "Timing functions in the flash.utils package" :
                        "These functions remain in ActionScript 3.0 for backward compatibility. Adobe does not recommend that you use them in new ActionScript 3.0 applications. In general, it is easier and more efficient to use the Timer class in your applications."

                        Just wanted you to be aware of this, in case something changes (Flex 4?) and it becomes unsupported or something, in which case your code may break.
                        • 9. Re: Measuring time
                          amvit Level 1
                          thanks buddy for bringing that up. I am very new to flex so do not know these things.I just wanted to measure the time to render the UI as part of Proof Of Concept.
                          Thanks once again,
                          • 10. Re: Measuring time
                            rtalton Level 4
                            Sure thing. I think I'd try the Date method, like Nathaniel Skiba suggested. It's more of a pain working with the date class, but probably more future-proof.