[Haskell-cafe] [Somewhat OT] Speed

wren ng thornton wren at freegeek.org
Tue Oct 28 21:20:09 EDT 2008

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 

Live well,

More information about the Haskell-Cafe mailing list