1 Reply Latest reply on Jun 5, 2006 10:02 AM by 2m

    Getting better performance

    ChrisFlynn
      Hi all

      I have a function that calls about 5 or 6 functions, and from these functions, about a 2 dozen or so processes gets called. Now from this first function that calls the 5 or 6 functions, I want to use a loop, so those functions get called about 300-500 times.

      So I have a lot of backend loops and functions happening, but I still want them to happen rather quickly. So I've tried looping this 300-500 count a few ways, first with an onEnterFrame like this:

      onEnterFrame = funtion(){
      if(count <=300){
      //call my 5 or 6 functions
      }else{
      delete onEnterFrame;
      }
      }

      Then with a setInterval call like this:

      theFunction = function(){
      if(count <= 300){
      //call functions
      }else{
      clearInterval(intervalID);
      }
      }
      intervalID = setInterval(this, theFunction, 1);

      Both ways, it takes about 30 seconds to complete all the tasks, which is fine, but I'm hoping to speed that up to 10 seconds if possible. Are their faster ways of doing this?

      Any help is always appreciated.

      Thanks
      Chris
        • 1. Re: Getting better performance
          2m Level 2
          as you don't give us the functins it is hard to tell, but if I read your example right it seems that it will make no difference if you ude setInterval or on enter frame, it seems the execution of one loop lasts for about 100 ms, and both time based events have to wait for one loop finishing before executing the next.

          with a frame rate of 5 per second your loop would last 60 sec (300 / 5). So setInterval is the better way to ensure that your code is executed without pause, if you mange to optimize that is.

          But there is one thing to consider:

          If the player isn't able to go to the next frame within 15sec, an error message is shown to the user, so the onEnterframe has it's advantages ;-)

          To be sure and fast, make sure that you do about as much loops as you can do savely even on the slowest mchines you are targeting in under 15 sec, and proceed to the next frame than and continue there. (It can be also a good thing to inform the user that something is still happening!)