title: Is integer multiplication really done at the same speed as addition on a modern CPU?
body: <p>I hear this statement quite often, that multiplication on modern hardware is so optimized that it actually is at the same speed as addition. Is that true?</p>
  
  <p>I never can get any authoritative confirmation. My own research only adds questions. The speed tests usually show data that confuses me. Here is an example:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;sys/time.h&gt;
  
  unsigned int time1000() {
      timeval val;
      gettimeofday(&amp;val, 0);
      val.tv_sec &amp;= 0xffff;
      return val.tv_sec * 1000 + val.tv_usec / 1000;
  }
  
  int main() {
      unsigned int sum = 1, T = time1000();
      for (int i = 1; i &lt; 100000000; i++) {
          sum += i + (i+1); sum++;
      }
      printf("%u %u\n", time1000() - T, sum);
      sum = 1;
      T = time1000();
      for (int i = 1; i &lt; 100000000; i++) {
          sum += i * (i+1); sum++;
      }
      printf("%u %u\n", time1000() - T, sum);
  }
  </code></pre>
  
  <p>The code above can show that multiplication is faster:</p>
  
  <pre><code>clang++ benchmark.cpp -o benchmark
  ./benchmark
  746 1974919423
  708 3830355456
  </code></pre>
  
  <p>But with other compilers, other compiler arguments, differently written inner loops, the results can vary and I cannot even get an approximation.</p>