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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:24:44+00:00 2026-06-15T16:24:44+00:00

Assuming the compiler does in fact inline foo is there a performance difference between

  • 0

Assuming the compiler does in fact inline foo is there a performance difference between these 2 statements?

inline int foo (int val) {
  return val;
}

int main () {

  std::cout << foo(123) << std::endl;

  std::cout << 123 << std::endl;

  return 0; 
}

Let’s ignore any implications that move semantics and copy elision might have.

  • 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-15T16:24:45+00:00Added an answer on June 15, 2026 at 4:24 pm

    My compiler (gcc 4.7.2) produces nearly identical code for the two statements:

    _main:
    LFB1018:
            pushq   %rbx
    LCFI0:
            movq    __ZSt4cout@GOTPCREL(%rip), %rbx
    
    ; std::cout << foo(123) << std::endl;
            movl    $123, %esi
            movq    %rbx, %rdi
            call    __ZNSolsEi
            movq    %rax, %rdi
            call    __ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
    
    ; std::cout << 123 << std::endl;
            movq    %rbx, %rdi
            movl    $123, %esi
            call    __ZNSolsEi
            movq    %rax, %rdi
            call    __ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
    
            xorl    %eax, %eax
            popq    %rbx
    LCFI1:
            ret
    

    The only difference is the order of the first two instructions. I’ve experimented with it, and this difference doesn’t appear to have anything to do with foo(): if I repeat the two lines twice, only the last of the four statements has the instruction order reversed. This makes me think that this artifact probably has something to do with the pipeline optimizer or something of that nature.

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

Sidebar

Related Questions

These are mostly compiler design questions. When your compiler compiles this, for example: int
Furthermore, how does the compiler determine the extent to unroll a loop, assuming all
Assuming I have a numerical string: var foo = 0; Assume I want to
I have a structure typedef struct foo { int lengthOfArray1; int lengthOfArray2; int* array1;
I wonder what is the best way to do this. val foo = Some(a)
Does it have an adverse effect on a browser's performance to assign class name
Assuming I have to use C (no C++ or object oriented compilers) and I
Assuming the webserver is configured to handle .exe , Can i compile a python
Assuming that I have this: enum { A = 0x2E, B = 0x23, C
Assuming all my Gradle plugin user going to have a MYAPP_HOME sys variable set

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.