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 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

I just edited the question to make it more clear.. please help I am
Moderator note: This question is not a good fit for our question and answer
Problem: edited files on windows, using git-bash, to fix IE7 problems committed, pushed to
I edited the question after David Hanak's answer (thanks btw!). He helped with the
This is a sample (edited slightly, but you get the idea) of my XML
I have HTML code edited by FCKEditor stored in a database and would like
How do I load the edited .emacs file without restarting Emacs?
I have a JavaScript resource that has the possibility of being edited at any
Here is an example of polymorphism from http://www.cplusplus.com/doc/tutorial/polymorphism.html (edited for readability): // abstract base
My VB.Net Winforms app is a tool to allow hierarchical data to be edited

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.