title: float vs double performance testing on beagle bone black
body: <p>I am doing some image processing on my Beaglebone Black and am interested in the performance gain of using floats vs doubles in my algorithm.</p>
  
  <p>I've tried to devise a simple test for this:</p>
  
  <h2>main.c</h2>
  
  <pre><code>#define MAX_TEST 10
  #define MAX_ITER 1E7
  #define DELTA 1E-8 
  
  void float_test()
  {
      float n = 0.0;
      for (int i=0; i&lt;MAX_ITER; i++)
      {
          n += DELTA;
          n /= 3.0;
      }
  }
  
  
  void double_test()
  {
      double n = 0.0;
      for (int i=0; i&lt;MAX_ITER; i++)
      {
          n += DELTA;
          n /= 3.0;
      }
  }
  
  
  int main()
  {
      for (int i=0; i&lt;MAX_TEST; i++)
      {
          double_test();
          float_test();
      }
  
      return 0;
  }
  </code></pre>
  
  <h2>ran as:</h2>
  
  <pre><code>gcc -Wall -pg main.c  -std=c99
  ./a.out
  gprof a.out gmon.out -q &gt; profile.txt
  </code></pre>
  
  <h2>profile.txt:</h2>
  
  <pre><code>granularity: each sample hit covers 4 byte(s) for 0.03% of 35.31 seconds
  
  index % time    self  children    called     name
                                                   &lt;spontaneous&gt;
  [1]    100.0    0.00   35.31                 main [1]
                 18.74    0.00      10/10          float_test [2]
                 16.57    0.00      10/10          double_test [3]
  -----------------------------------------------
                 18.74    0.00      10/10          main [1]
  [2]     53.1   18.74    0.00      10         float_test [2]
  -----------------------------------------------
                 16.57    0.00      10/10          main [1]
  [3]     46.9   16.57    0.00      10         double_test [3]
  -----------------------------------------------
  </code></pre>
  
  <p>I am not sure if the compiler is optimizing away some of my code or if I am doing enough arithmetic for it to matter.  I find it a bit odd that the double_test() is actually taking less time than the float_test().</p>
  
  <p>I've tried switching the order in which the functions are called and they results are still the same.  Could somebody explain this to me?</p>