For Each Is Fastest
I was doing some coding where optimization really mattered and made a little loop test. The ‘for each’ loop is the fastest - even when you need an index.
Also of note, the debug player has ‘incrementing while’ as faster than the ‘do while.’ And both as faster than ‘for each with counter.’ There is a huge difference between the performance of the debug and the release player in Flex. (Using the Flex Beta 3 Release 3 here.) Check out my friend James’ test for more info on the diffs. He has a lot of benchmarking around typing vars here. Those posts completely refute some earlier, widely read, posts that suggested you should never use int. Lesson here is, make sure you test performance with a version published for release. Unfortunately, that means you can’t trust trace statements for your benchmarking. You need to put your time displays in a text field.
Also, I did some tests, and it appears that ‘for each’ preserves order - which is obviously very important to know. If you have found different, please post a comment. Example here. View source enabled.