title: Putting execution timing code into a function, OpenCV?
body: <p>I have this code snippet that I use everywhere in my programs (C++ and OpenCV). It is for timing some operations:</p>
  
  <pre><code>double t;
  
  // Some code...
  
  t = (double)getTickCount();
  
  Object1.LotOfComputing();
  
  t = 1000*((double)getTickCount() - t)/getTickFrequency();
  cout &lt;&lt; "Time for LotOfComputing =" &lt;&lt; t &lt;&lt; " milliseconds."&lt;&lt; endl;
  cout &lt;&lt; "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" &lt;&lt; endl;
  </code></pre>
  
  <p>This is how the OpenCV doc recommend to time a function/portion of code and it seems to works for me after using it for some weeks. The times I measure are ranging from about 1ms to 700ms, and I round them to the millisecond.</p>
  
  <p>The problem is that I time a lot of different operations in my program and the code is cluttered by these snippets.</p>
  
  <p>I wonder if it would be wise to put these lines of code into a function, like:</p>
  
  <pre><code>double timing(double time){
  
  timing = 1000*((double)getTickCount() - time)/getTickFrequency();
  cout &lt;&lt; "Time for LotOfComputing =" &lt;&lt; timing &lt;&lt; " milliseconds."&lt;&lt; endl;
  cout &lt;&lt; "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" &lt;&lt; endl;
  
  return timing;
  
  }
  </code></pre>
  
  <p>So I could be able to use this:</p>
  
  <pre><code>double t;
  
  // Some code...
  
  t = (double)getTickCount();
  
  Object1.LotOfComputing();
  
  timing(t);
  </code></pre>
  
  <p>I am simply concerned about the execution time of going through function calls... Maybe I am simply worrying for nothing!</p>