Hi and thanks for your deep explanation :) and yes I run the profiler,
and are doing some improvement here and there, the real question is
how the "for each" is working. I have been browsing the internet and
all the bibels on ActionScript 3, but did not found any good
explanation on the matter.


--- In flexcoders@yahoogroups.com, Maciek Sakrejda <[EMAIL PROTECTED]> wrote:
>
> If you're trying to speed up your application, you should use the
> profiler. Something like the difference between a "manually" indexed for
> loop and a for-each loop is almost certain to be trivial.
> 
> If you don't have the profiler, run an ad-hoc perf test by doing
> something like
> 
> // we need to construct something to iterate over:
> var iterations:int = 1000000;
> var arr:Array = [];
> for (var i:int = 0; i < iterations; i++) arr.push(i);
> var dummy:int = 0;
> 
> var forBeginning:Number = new Date().getTime();
> for (var j:int = 0; j < iterations; j++)
> {
> // we need to do something in the loop so the whole thing
> // is not just optimized out (not sure if FP does this, but
> // it can), but we don't want to use trace() since I/O is
> // relatively expensive compared to the cost of the loop itself
> dummy = arr[j];
> } 
> trace("for loop took " + (new Date().getTime() - forBeginning) + "
> milliseconds");
> 
> var forEachBeginning:Number = new Date().getTime();
> for each (var k:int in arr)
> {
> dummy = k;
> }
> trace("for-each loop took " + (new Date().getTime() - forEachBeginning)
> + " milliseconds");
> 
> That should give you an idea of the difference (but run this many times
> and average it, and vary the order of the loops). Also, keep in mind
> that most of the time, you won't be iterating over a million items.
> Bottlenecks can occur in surprising places (though they're often found
> in common places too, like Container layout code). Don't try to optimize
> things that *seem like* they would be slow without actually confirming
> not only that they *are* slow, but that they are affecting the overall
> speed or responsiveness of your application. It makes no sense to make a
> 10x performance improvement in one part of your code that accounts
> for .01% of your application's CPU usage.
> 
> -- 
> Maciek Sakrejda
> Truviso, Inc.
> http://www.truviso.com
> 
> -----Original Message-----
> From: Cato Paus <[EMAIL PROTECTED]>
> Reply-To: flexcoders@yahoogroups.com
> To: flexcoders@yahoogroups.com
> Subject: [flexcoders] speed of the "for each" looping
> Date: Tue, 09 Dec 2008 13:28:23 -0000
> 
> Hi, all you experts :)
> 
> I'm tying to speed up my application and I use a lot of
> 
> exsample
> for (var i:int = 0; i < 5; i++)
> {
> trace(i);
> } 
> 
> so is the "for each" looping faster ?
>


Reply via email to