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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:43:34+00:00 2026-05-31T02:43:34+00:00

I noticed this accidentally one day, and now decided to test it extensively. So,

  • 0

I noticed this accidentally one day, and now decided to test it extensively.

So, when I call a function:

#define Type int
#define Prm const Type &
Type testfunc1(Prm v1, Prm v2, Prm v3, Prm v4, Prm v5, Prm v6, Prm v7, Prm v8, Prm v9, Prm v10){
    return (v1|v2|v3|v4|v5|v6|v7|v8|v9|v10);
}

100 million times:

        for(Type y = 0; y < 10000; y++){
            for(Type x = 0; x < 10000; x++){
                out |= testfunc1(x,y,x,x,y,y,x,y,x,y);
            }
        }

With types int, const int and const int &, i notice that const int is faster than const int &. (Note: im using the return value to ensure the function wont get optimized off).

Why is it so? I always thought adding & would actually make it faster, but the tests say the opposite. I know for bigger datatypes it would probably be different outcome, I didnt test those though since I’m quite sure about the results.

My tests:

const int: 7.95s
const int &: 10.2s

Edit: I think it is indeed because of my architecture; I tested with Sint64 type and the results were:

const Sint64: 17.5s
const Sint64 &: 16.2s

Edit2: Or is it? Tested with double type (which is 64bit?), and results make me puzzled:

const double: 11.28s
const double &: 12.34s

Edit3: updated the loop code to match my newest tests with 64bit types.

  • 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-31T02:43:36+00:00Added an answer on May 31, 2026 at 2:43 am

    By putting a & into the argument, you are adding more code to the program. Without the &, the sequence is:

     push values
     call Function
     pop values <- usually an update to stack pointer
    

    and in Function:

     return sp[arg1] | sp[arg2] | etc <- value read direct from stack.
    

    Adding the ‘&’ does this:

     push address of value1
     push address of value2
     etc
     call Function
     pop values <- usually an update to stack pointer
    

    and in Function:

     return_value = 0;
     address = sp[arg1]
     or return_value, [address]
     address = sp[arg2]
     or return_value, [address]
     etc
     return return_value
    

    So, as you can see, the & adds a lot. So why use it? If you have a very large object, passing a pointer is more optimal than copying the object to the stack.

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

Sidebar

Related Questions

I noticed this in earlier versions of Visual Studio. But now i use VS
I noticed this method for setting options for Firebug Lite: http://getfirebug.com/firebuglite#ScriptJSONOptions <script type=text/javascript src=https://getfirebug.com/firebug-lite.js>
I noticed this the other day, say you have two overloaded methods: public void
I noticed this semi weirdish-behavior in one of my projects using Scheme and lists.
Noticed this today when a patch was submitted with the following line: lblCompletionTime.Text =
Just noticed this on OSX and I found it curious as I expected long
I noticed This question , but my question is a bit more specific. Is
I just noticed this about a week ago. I'm storing data about the current
I just recently noticed this behaviour. To put it shortly, it displays the commits
I was browsing through the questions and noticed this: SELECT prodid, issue FROM Sales

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.