Note that there are some explanatory texts on larger screens.

plurals
  1. POSame function differing in parameter type - passing by value/reference
    primarykey
    data
    text
    <p>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.</p> <p>Hello All:</p> <p>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.</p> <p>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.</p> <p>For instance, in the header file, could I define something like</p> <pre><code>#define PBV 0 //0 value here indicates I want to PBR, 1 value here indicates I want to PBV </code></pre> <p>Once this is defined, is something like the following valid in the function declaration section?</p> <pre><code>#if PBV == 0 // I want to PBR function_to_call(Class1&amp; class1object);//PBR function declaration #elif PBV == 1 // I want to PBV function_to_call(Class1 class1object);//PBV function declaration #endif </code></pre> <p>Then, in the source code, I can simply have</p> <pre><code>function_to_call(class1object); </code></pre> <p>and whether this call translates into a PBV or PBR would depend on #define PBV I have in the header section.</p> <p>If this is not the right way to go, any pointers to the right direction would be highly appreciated.</p> <p>Also, if this way is decent, wouldn't I have to specify in the body of my code the following:</p> <pre><code>function_to_call(Class1&amp; class1object){//Actual function details for PBR //Stuff } </code></pre> <p>and </p> <pre><code>function_to_call(Class1 class1object){//Actual function details for PBV //Stuff } </code></pre> <p>with //Stuff being repeated twice? Is there a way this can be avoided somehow?</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload