title: Different execution times between pow and powf of standard math.h library in c programming
body: <p>I'm currently benchmarking several algorithms in C code. I recognized the following behavior I cannot explain:</p>
  <p>When comparing the execution times of the <code>pow()</code> and <code>powf()</code> function of the math.h library, executing the <code>powf()</code> function is two times slower than <code>pow()</code>.</p>
  <p>I used <code>powf()</code> with float values only and pow() with double values, so there should not be any implicit type conversion.</p>
  <p>I execute the code on a beaglebone black and using gcc to compile it. Currently, I do not use any optimization flags. If using <code>-O3</code>, the execution times are nearly the same.</p>
  <p>Is there an explanation why <code>powf()</code> is so much slower?</p>
  <p>Here is a minimal example of what I did:</p>
  <pre><code>#include&lt;time.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  
  struct timespec diff_time(struct timespec start, struct timespec end)
  {
      struct timespec temp;
      if ((end.tv_nsec - start.tv_nsec) &lt; 0) {
          temp.tv_sec = end.tv_sec - start.tv_sec - 1;
          temp.tv_nsec = 1000000000 + end.tv_nsec - start.tv_nsec;
      }
      else {
          temp.tv_sec = end.tv_sec - start.tv_sec;
          temp.tv_nsec = end.tv_nsec - start.tv_nsec;
      }
      return temp;
  }
  
  int main() {
  
      struct timespec time1, time2;
      double time_diff; 
  
      double result=0;
      float resultf=0;
  
      double value = 234.2348;
      float valuef = 234.2348f;
  
      int j;
  
      int select_switch = 1; 
  
      //TIC
      clock_gettime(CLOCK_REALTIME, &amp;time1);
  
      
      if (select_switch == 1) {
  
          for (j = 0; j &lt; 1000; j++)
          {
              result = pow(value, 2);
          }
      }
  
      if (select_switch == 2) {
          for (j = 0; j &lt; 1000; j++)
          {
              resultf = powf(valuef, 2.0f);
          }
      }
  
      if (select_switch == 4) {
          for (j = 0; j &lt; 1000; j++)
          {
              resultf = valuef * valuef;
          }
      }
  
  
      if (select_switch == 5) {
          for (j = 0; j &lt; 1000; j++)
          {
              result = value * value;
          }
      }
  
      /* TOC */
  
      clock_gettime(CLOCK_REALTIME, &amp;time2);
      time_diff = diff_time(time1, time2).tv_sec * (1e3) +
          (diff_time(time1, time2).tv_nsec) * (1e-6); // in Milli Seconds 
  
      printf(&quot;%lf&quot;, result); 
      printf(&quot;%f&quot;, resultf); 
  }
  </code></pre>