Richard O'Keefe wrote:
Rough guesses:
 integer adds, subtracts, and compares are fast,
 integer multiplies and divides are much slower,
 slow enough that compilers go to some trouble to
 do something else when multiplying or dividing
 by a constant.

Typically, these days (for both int and fp)...

Multiply is somewhat slower than addition (1x~4x). Many compilers will go through efforts to convert multiplications into additions, shifts, etc, but that code is mostly legacy from when multiplication was in the 8x~12x range.

Division is much slower than multiplication (10x~40x). Many compilers will do all they can to convert these into simpler operations whenever possible. When in doubt, performance programmers tend to do the same.

Logarithms/exponentiation are also much, much slower than multiplication. I'm not aware of any compilers that try to optimize these in any meaningful way. (Though for a very particular task, see the logfloat package <http://hackage.haskell.org/cgi-bin/hackage-scripts/package/logfloat>.)

--
Live well,
~wren
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to