title: Measuring runtime with counter variable
body: <p>I am currently working on an assignment which asks us to implement a few different sorts and introduce counter variables to measure the runtime.</p>
  
  <p>My question is that I'm confused about whether or not to include certain "operations" as something that would increment my counter. For instance, my textbook says this:</p>
  
  <p><img src="https://i.stack.imgur.com/oYKZa.png" alt="">
      ....</p>
  
  <p>So, from what I understand, I should be counting "comparisons" but I do not understand if this applies to if statements, while loops, etc. </p>
  
  <p>For instance, here is my insertion sort.</p>
  
  <pre><code>float insertionSort(int theArray[], int n) {
      float count = 0;
  
      for (int unsorted = 1; unsorted &lt; n; unsorted++) {
          int nextItem = theArray[unsorted];
          int loc = unsorted;
  
          while ((loc &gt; 0) &amp;&amp; (theArray[loc - 1] &gt; nextItem)) {
              theArray[loc] = theArray[loc - 1];
              theArray[loc] = nextItem;
              loc--;
              count += 4;
          }
      }
  
      return count;
  }
  </code></pre>
  
  <p>As you can see, I increment count by 4 for each iteration of the while loop. This really highlights my question, I think. </p>
  
  <p>My reasoning is that we make two comparisons in the conditional statement of the while loop:</p>
  
  <p>(loc > 0 &amp;&amp; theArray[loc - 1] > nextItem)</p>
  
  <p>Afterwards, we make two moves in the array. From my understanding, this means that we have performed 4 "operations" and we would increment counter by 4 for the sake of measuring runtime at the end of execution.</p>
  
  <p>Is this correct? Thank you SO much for any help.</p>