Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In <code>c++11</code> you have the <code>std::chrono</code> library (see <a href="http://en.cppreference.com/w/cpp/chrono" rel="nofollow">std::chrono)</a>. Otherwise, you can use <code>boost::chrono</code> (see <a href="http://www.boost.org/doc/libs/1_53_0/doc/html/chrono.html" rel="nofollow">boost::chrono</a>). Those 2 are very basic time measurement libraries you can start with. </p> <p>EDIT: In c++0x you have the <code>clock()</code> function - but as noted in the comment section - it is not a very accurate measurement. Plus, most platforms also supply some sort of API for chrono-related operations.</p> <p>How to measure performance depends on the context. First, you'll want to compare performance on a large enough and diverse enough sample data. Large enough means that it is at least measurable in seconds. Diverse enough means that it covers repetition of all run scenarios either uniformly or perhaps separately (you should at lease know what cut the sample data represents).</p> <p>For simple enough cases, the first thing you'll want to do is partition your algorithm into as many as needed segments, let's call them <code>A_1,...,A_N</code> (or perhaps <code>A_1...A_N</code> are different solutions to the same problem, the concept still holds). What you'll want to do is measure the amount of time spent on each partition over the same sample data. In pseudo-code:</p> <pre><code>times &lt;- (0,...,0) //vector of size N for each input in sample data: start = now() //Run A_1 on input end = now() times[1] &lt;- times[1] + (end-start) ... ... ... start = now() //Run A_N on input end = now() times[N] &lt;- times[N] + (end-start) </code></pre> <p>At the end of this run you are left with a times vector which shows you how much time you've spent in each element. <strong>That is the most basic approach. But the key element to profiling is: there are many ways to dissect a frog</strong>. You could also look at how much time you are spending on a specific operation which could be called from many partitions of the algorithm. You could choose to look at the number of load/store operations, cache performance etc. The variations are numerous and great reward can often come from unexpected sources (at least to the unwary observer).</p> <p>For more advanced profiling, you can use a 3rd party profiling framework (some IDEs come with built-in profiling capabilities).</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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