title: Pass by value faster than pass by reference
body: <p>I made a simple program in c++ to compare performance between two approaches - pass by value and pass by reference. Actually pass by value performed better than pass by reference.</p>
  
  <p>The conclusion should be that passing by value require fewer clock-cycles (instructions)</p>
  
  <p>I would be really glad if someone could explain in detail <strong>why</strong> pass by value require fewer clock-cycles.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  
  using namespace std;
  
  void function(int *ptr);
  void function2(int val);
  
  int main() {
  
     int nmbr = 5;
  
     clock_t start, stop;
     start = clock();
     for (long i = 0; i &lt; 1000000000; i++) {
         function(&amp;nmbr);
         //function2(nmbr);
     }
     stop = clock();
  
     cout &lt;&lt; "time: " &lt;&lt; stop - start;
  
     return 0;
  }
  
  /**
  * pass by reference
  */
  void function(int *ptr) {
      *ptr *= 5;
  }
  
  /**
  * pass by value
  */
  void function2(int val) {
     val *= 5;
  }
  </code></pre>