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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:26:38+00:00 2026-05-18T02:26:38+00:00

Edited: Please note, when I mention performance comparison, it is not performance comparison of

  • 0

Edited: Please note, when I mention performance comparison, it is not performance comparison of C++ pass-by-reference vs. pass-by-value. It is more to test whether the underlying algorithm of CPLEX (to solve linear programs) runs better when CPLEX objects are passed by value or passed by reference.

Hello All:

I need to test the performance of a program when a function’s parameters are passed by value (PBV) and when the same function’s parameters are passed by reference (PBR). There is a library I am using (IBM ILOG CPLEX, used for Operations Research/Linear Programming related work) where objects of classes in that library can be PBV and PBR as per the library’s manual which unfortunately is silent about the efficacy of one over the other. I just want to test whether the choice of one over the other may lead to performance issues.

A brute-force way to test this might be to have two source code files, source_pbv.cpp and source_pbr.cpp, where the former has all functions PBV and the latter has all functions PBR. This is pretty difficult to maintain. I was wondering how, if at all, I can go about testing the performance using a single .cpp file.

For instance, in the header file, could I define something like

#define PBV 0 //0 value here indicates I want to PBR, 1 value here indicates I want to PBV

Once this is defined, is something like the following valid in the function declaration section?

#if PBV == 0 // I want to PBR
     function_to_call(Class1& class1object);//PBR function declaration
#elif PBV == 1 // I want to PBV
     function_to_call(Class1 class1object);//PBV function declaration
#endif

Then, in the source code, I can simply have

function_to_call(class1object);

and whether this call translates into a PBV or PBR would depend on #define PBV I have in the header section.

If this is not the right way to go, any pointers to the right direction would be highly appreciated.

Also, if this way is decent, wouldn’t I have to specify in the body of my code the following:

function_to_call(Class1& class1object){//Actual function details for PBR
    //Stuff
}

and

function_to_call(Class1 class1object){//Actual function details for PBV
    //Stuff
}

with //Stuff being repeated twice? Is there a way this can be avoided somehow?

Thanks.

  • 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-18T02:26:39+00:00Added an answer on May 18, 2026 at 2:26 am

    Here is what worked for me…

    #define PBV 0  //0 means PBR, 1 means PBV
    #if PBV == 0
        #define PCLASS1 Class1&
    #elif PBV == 1
        #define PCLASS1 Class1
    #endif
    
    void function_to_call(PCLASS1 class1object){
    //depending on PBV, PCLASS1 above will be either Class1& or Class1
        //Stuff
    }
    

    This way, I did not have to have //Stuff in two functions. I just need to change my code in one location to switch between PBR and PBV.

    Thanks for your help.

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

Sidebar

Related Questions

Please note it is not a NSComboBox, but a NSComboBoxCell. Also, note I'm on
--- Edited below with some more testing, please read :) --- I'm struggling trying
EDIT: Please note that the app comes up just fine in Passenger/Apache2. Just not
EDITED still not sure whats wrong please help hi there I'm creating and iOS
I just edited the question to make it more clear.. please help I am
Please note, sarnold has heavily edited the question; the original question, in its entirety,
Edit my code to make it work please. Edited for latest version. Here is
EDITED I'm using Twitter Bootstrap and need to move navbar right( not float:right, but
Edited: SOLUTION FOUND. This is strange and not the best solution, but I just
Please let me know if I need to provide more/different parts of my program

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.