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

  • SEARCH
  • Home
  • 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 4265208
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:35:33+00:00 2026-05-21T06:35:33+00:00

I have recently begun to think about optimisation, now I know there are many

  • 0

I have recently begun to think about optimisation, now I know there are many books and articles but I have a particular scenario i’m interested in.

A.

for (i = 0; i < limit + 5; i++)
  cout << test;

B.

limit2 = limit +5;
for (i = 0; i < limit2; i++)
  cout << test;

What I want to know is would the second piece of code run faster because it only has to do the mathematical calculation once or is the calculation stored for the lifetime of the loop.

  • 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-21T06:35:34+00:00Added an answer on May 21, 2026 at 6:35 am

    You’re focusing on an optimization that almost certainly doesn’t matter, regardless of how it gets compiled. Focus on picking the right algorithms and design for the rest of your code. Profile to find out what’s slow and optimize the areas that take the most time. Typically 10% of the code takes 90% of the time. You’re currently thinking about a very small part of the 90% of the code that takes far less than 10% of the time in just about every possible scenario beyond having an empty loop block.

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

Sidebar

Related Questions

I've recently begun learning C# but have encountered an annoying problem. Every variable I
I usually script/program using python but have recently begun programming with JavaScript and have
Hey there everyone. I have recently begun tweaking the new default wp theme, twenty
I have recently begun delving into the world that is database programming with C++
I have recently begun working on a pre-existing PHP application, and am having a
I have recently found myself becoming more negative about EF and cannot help wondering
I've recently begun working on Django and now my app is nearing completion and
I have recently begun experiencing several odd issues with the Android SDK and I
I have recently begun a new project which runs on remote computer. I usually
I've recently begun a fairly small 2D project using SFML and TinyXML and have

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.