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 522561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:22:01+00:00 2026-05-13T08:22:01+00:00

Using the latest gcc compiler, do I still have to think about these types

  • 0

Using the latest gcc compiler, do I still have to think about these types of manual loop optimizations, or will the compiler take care of them for me well enough?

  • 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-13T08:22:01+00:00Added an answer on May 13, 2026 at 8:22 am

    If your profiler tells you there is a problem with a loop, and only then, a thing to watch out for is a memory reference in the loop which you know is invariant across the loop but the compiler does not. Here’s a contrived example, bubbling an element out to the end of an array:

    for ( ; i < a->length - 1; i++)
        swap_elements(a, i, i+1);
    

    You may know that the call to swap_elements does not change the value of a->length, but if the definition of swap_elements is in another source file, it is quite likely that the compiler does not. Hence it can be worthwhile hoisting the computation of a->length out of the loop:

    int n = a->length;
    for ( ; i < n - 1; i++)
        swap_elements(a, i, i+1);
    

    On performance-critical inner loops, my students get measurable speedups with transformations like this one.

    Note that there’s no need to hoist the computation of n-1; any optimizing compiler is perfectly capable of discovering loop-invariant computations among local variables. It’s memory references and function calls that may be more difficult. And the code with n-1 is more manifestly correct.

    As others have noted, you have no business doing any of this until you’ve profiled and have discovered that the loop is a performance bottleneck that actually matters.

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

Sidebar

Related Questions

I have been using the gcc compiler with code::blocks ide, and have noticed there
I am using latest Apache CXF to create a webservice. I have configured ws-security
I am using latest PHP and latest MySQL. I have tried htmlspecialchars and mysql_real_escape_string
I have Debian 6.04 , and the latest gcc version included is gcc 4.4
Does anybody using latest enterprise library 4.1 in mono? I used mono migration analyzer
Currently I'm building an application using latest Prism for Silverlight 4. I've a module
Using the latest version of Resharper (4.5.x) with VS2008. Every now and then (pretty
I'm using the latest nightly build, VS2008 prof trial and .NET 3.5 and I'm
I am using the latest NHibernate 2.1.0Beta2. I'm trying to unit test with SQLite
I'm using the latest WPF toolkit , specifically the DatePicker . Everything works fine,

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.