[Haskell-beginners] division / multiplication efficiency
Brent Yorgey
byorgey at seas.upenn.edu
Wed Nov 28 16:20:01 CET 2012
On Wed, Nov 28, 2012 at 04:02:38AM -0900, Christopher Howard wrote:
> Say I have functions like so:
>
> code:
> --------
> circleRadians = 2 * pi
>
> radius = (/ circleRadians)
> --------
>
> My question: each time I call radius, will a division operation be
> performed?
Probably yes.
> Is there anything to be gained, following the old adage that
> multiplication is more efficient than division in hardware, from
> something like:
>
> code:
> --------
> radius = (* (1 / circleRadians))
> --------
If this actually makes a difference (and isn't dwarfed by other
considerations), then you have some very fiddly, low-level, tightly
optimized code indeed. And modern processors are so fancy and
complex, the real answer is probably "it depends", anyway. If you
really think it matters, then profile an actual program to see the
difference (using e.g. the 'criterion' package).
But the REAL answer is, "you have better things to do with your time
than worry about this".
-Brent
More information about the Beginners
mailing list