title: How can I compare the performance of log() and fp division in C++?
body: <p>I’m using a log-based class in C++ to store very small floating-point values (as the values otherwise go beyond the scope of <code>double</code>). As I’m performing a large number of multiplications, this has the added benefit of converting the multiplications to sums.</p>
  
  <p>However, at a certain point in my algorithm, I need to divide a standard <code>double</code> value by an <code>integer</code> value and than do a <code>*=</code> to a log-based value. I have overloaded the <code>*=</code> operator for my log-based class and the right-hand side value is first converted to a log-based value by running <code>log()</code> and than added to the left-hand side value.
  Thus the operations actually performed are floating-point division, <code>log()</code> and floating-point summation.</p>
  
  <p>My question whether it would be faster to first convert the denominator to a log-based value, which would replace the floating-point division with floating-point subtraction, yielding the following chain of operations: twice <code>log()</code>, floating-point subtraction, floating-point summation.</p>
  
  <p>In the end, this boils down to whether floating-point division is faster or slower than <code>log()</code>. I suspect that a common answer would be that this is compiler and architecture dependent, so I’ll say that I use gcc 4.2 from Apple on darwin 10.3.0. Still, I hope to get an answer with a general remark on the speed of these two operators and/or an idea on how to measure the difference myself, as there might be more going on here, e.g. executing the constructors that do the type conversion etc.</p>
  
  <p>Cheers!</p>