Jump to content
  • Advertisement
Sign in to follow this  
HumanoidTyphoon

Perl Efficiency Question (Declaring inside loop)

This topic is 3943 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Would just like to ask.. Right now im declaring indexed arrays (@) inside a loop for scope reasons. The values obviously change every iteration. Im wondering if there would be an efficiency issue with this? This script needs to be as efficient as possible, atleast for the first run! Its a purging script and 4 years worth of data needs to be purged. Would declaring these arrays outside the loop be more efficient for the first run? I like scoping correctly so either way they will live in the loop after the first run as the script will be run more often and efficiency would not be as important as scoping anymore. How would the different options affect the stack? Thanks [Edited by - HumanoidTyphoon on October 31, 2007 8:39:20 AM]

Share this post


Link to post
Share on other sites
Advertisement
How about trying it both ways on a small data set, and comparing the results?

Sorry about generic answer, but I find that unless you're working with really low level code and algorithms in absolutely real-time critical application in a bare bones language, this type of premature optimization is rarely successful.

Share this post


Link to post
Share on other sites
In general and especially in scripting languages, object construction is a slow operation, so declaring them outside the loop will probably be faster.

Share this post


Link to post
Share on other sites
Quote:
Original post by Konfusius
In general and especially in scripting languages, object construction is a slow operation, so declaring them outside the loop will probably be faster.

Then you have to modify your algorithm to explicitly empty and repopulate the sequence on each iteration. Which might end up being more expensive, depending on the number of objects.

Personally, I say go for semantic clarity first, then profile, then optimize. In other words, keep the object declaration inside the loop until you know that it is slowing down your algorithm.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!