Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6551987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:24:18+00:00 2026-05-25T12:24:18+00:00

I’ve been reading about about code optimization (to be more precise, code optimization for

  • 0

I’ve been reading about about code optimization (to be more precise, code optimization for ActionScript 3), and I have a few questions.

  1. Which is better, negative loops (i.e. counting backwards in loops and checking if you reach zero) or foreach loops? Both options seem to be better than normal “for” loops, but which is faster of the two?

  2. Which is better, using Numbers or ints?

  3. Does constant really decrease your performance?

I’ve tried writing a simple code and testing those myself, but the results were all over the place, and some of the websites I visited kinda had contradicting opinions!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:24:18+00:00Added an answer on May 25, 2026 at 12:24 pm

    “1) Which is better, negative loops (i.e. counting backwards in loops and checking if you reach zero) or foreach loops? Both options seem to be better than normal “for” loops, but which is faster of the two?”

    By foreach, I’m going to assume you mean for..each or for..in loops. As Demian pointed out, forEach is pretty slow. For the others, doing a simple for loop is always quicker (you can early out of all of them except forEach I think) by just returning when you hit the check you need). Whether you do i++ or i– makes no difference. for..each and for..in loops have their benefits though. for..in is the only way you can loop through Dictionary and Object objects, while for..each performs the cast for you, meaning you write less code. As in:

    for each( var s:Sprite in this.m_mySpriteVector )
        ...
    

    vs.

    var len:int = this.m_mySpriteVector.length;
    for( var i:int = 0; i < len; i++ )
        var s:Sprite = this.m_mySpriteVector[i];
    

    (on a side note, if you’re doing a normal for loop, taking out the length is the best thing you can do to speed it up). Also note that the speed difference in for loops only really matter if they’re large loops. If you’re doing a loop of 10, then it doesn’t really make any difference which one you pick.

    “2) Which is better, using Numbers or ints?”

    If you mean in loops, then always go for the int. In other general terms, use the class that represents what you need. If you only need whole numbers, then use int or uint. If you need decimals, then go for Number. Use the wrong type and you do incur a small penalty, but not a huge one. Also, depending on what you hold in the variable, it mightn’t be the type you think: http://jacksondunstan.com/articles/1357

    “3) Does constant really decrease your performance?”

    I’ve not really tested it, but probably not enough to really matter. Make a simple loop using 1,000,000 iterations or something and see if it makes a difference. Using a static const will incur a small penalty as it has to perform the class lookup, but it’s not harsh


    The final point to be made is to be careful about optimisation. Also have it in your head so you don’t write code that sucks, but be careful where you apply it. Optimised code usually takes longer to write and is less readable than other code (the for..each loops being a good example).

    Take into account where each piece of code is used. If it’s what’s called performance critical code – code that’s called all the time (ENTER_FRAME, or common functions) then that’s where you should focus your efforts. If it’s a function that’s called once, or not very often, then the time you spend optimising it will be a waste as you’re getting very little benefit from it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.