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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:52:24+00:00 2026-06-09T16:52:24+00:00

The training materials from the class I took seem to be making two conflicting

  • 0

The training materials from the class I took seem to be making two conflicting statements.

On one hand:

“Use of inline functions usually results in faster execution”

On the other hand:

“Use of inline functions may decrease performance due to more frequent
swapping”

Question 1: Are both statements true?

Question 2: What is meant by “swapping” here?

Please glance at this snippet:

int powA(int a, int b) {
  return (a + b)*(a + b) ;
}

inline int powB(int a, int b) {
  return (a + b)*(a + b) ;
}

int main () {
    Timer *t = new Timer;

    for(int a = 0; a < 9000; ++a) {
        for(int b = 0; b < 9000; ++b) {
             int i = (a + b)*(a + b);       //              322 ms   <-----
            //  int i = powA(a, b);         // not inline : 450 ms
            //  int i = powB(a, b);         // inline :     469 ms
        }
    }

    double d = t->ms();
    cout << "-->  " << d << endl; 

    return 0;
}

Question 3: Why is performance so similar between powA and powB? I would have expected powB performance to be along 322ms, since it is, after all, inline.

  • 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-06-09T16:52:26+00:00Added an answer on June 9, 2026 at 4:52 pm

    Question 1

    Yes, both statements can be true, in particular circumstances. Obviously they won’t both be true at the same time.

    Question 2

    “Swapping” is likely a reference to OS paging behaviour, where pages are swapped out to disk when the memory pressure becomes high.

    In practice, if your inline functions are small then you will usually notice a performance improvement due to eliminating the overhead of a function call and return. However, in very rare circumstances, you may cause code to grow such that it cannot completely reside inside the CPU cache (during a performance-critical tight loop), and you may experience decreased performance. However, if you’re coding at that level then you probably should be coding directly in assembly language anyway.

    Question 3

    The inline modifier is a hint to the compiler that it might want to consider compiling the given function inline. It doesn’t have to follow your directions, and the result may also depend on the given compiler options. You can always look at the generated assembly code to find out what it did.

    Your benchmark may not even be doing what you want because your compiler might be smart enough to see that you’re not even using the result of the function call that you assign into i, so it might not even bother to call your function. Again, look at the generated assembly code.

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

Sidebar

Related Questions

I'm trying to put together SharePoint 2007 (and, eventually, 2010) training materials for experienced
I'm training code problems like UvA and I have this one in which I
I am currently picking up Grails and Roo. The vast majority of training materials
I was reading Microsoft's Class Room Training Materil. I read the following Unboxing Unboxing
For training, I'm trying to write a class like std::string. I have read that
I'm just doing some formal training in Agile at the moment and one question
Recently I attended Jeffrey Richter's training courses about .NET. He mentions one strategy of
I took a training on BizTalk 2010 and found very help but I got
I am preparing some training materials in C and I want my examples to
For an algorithm competition training (not homework) we were given this question from a

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.