title: Performance of modulus operator in C
body: <p>From the execution time perspective, is using modulus operator more beneficial or the manual way of doing it if i am supposed to do the modulus thing a large number of times, about 10^6 times ?<br>
  Manually doing (number % mod_number) :</p>
  
  <pre><code>while(number &gt;= mod_number) {
       number = number - mod_number;
  }
  </code></pre>
  
  <p>Doing the same thing using % operator :</p>
  
  <pre><code>number = number % mod_number;
  </code></pre>
  
  <p>From what i have tested, manually doing it gives better time performance.
  How is the modulus operator defined? I know the outputs for negative numbers are implementation defined, i am asking about the working of the operator, i.e., its complexity so that i can justify the better manual performance.<br>
  <b>Note :</b> The question is specifically for implementation in C.<br>
  The code snippet:<br></p>
  
  <pre><code>for (j = 0; j &lt; idx; j++) {
              num = mark[j];
              dif = k - num;
              if (dif &lt; 0) dif = (-1 * dif) + 100;
              many = count[num];
              prev = ap[dif][k];
              ap[dif][k] = ap[dif][k] + ap[dif][num];
              //the manual way here works faster than %
              if (ap[dif][k] &gt;= mod) ap[dif][k] -= mod;
              ap[dif][k] += many;
              if (ap[dif][k] &gt;= mod) ap[dif][k] -= mod;
              sum = (sum + ap[dif][k]);
              if (sum &gt;= mod) sum -= mod;
              sum = sum - prev;
  }
  </code></pre>
  
  <p>The above loop is executed 2*(10^5)*t times with 'idx' gradually increasing till 100 for each 't'. Used t = 10.</p>