Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. division / multiplication efficiency (Christopher Howard)
2. Re: division / multiplication efficiency (Brent Yorgey)
3. Re: division / multiplication efficiency (KC)
4. Re: division / multiplication efficiency (Michael Orlitzky)
----------------------------------------------------------------------
Message: 1
Date: Wed, 28 Nov 2012 04:02:38 -0900
From: Christopher Howard <[email protected]>
Subject: [Haskell-beginners] division / multiplication efficiency
To: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
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? 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))
--------
...imagining that the compiler (or runtime graph reduction mechanism)
will transform (1 / circleRadians) into a single number (s) only once,
and use (* s) in all applications of radius?
--
frigidcode.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 551 bytes
Desc: OpenPGP digital signature
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20121128/5e238bd2/attachment-0001.pgp>
------------------------------
Message: 2
Date: Wed, 28 Nov 2012 10:20:01 -0500
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] division / multiplication efficiency
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
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
------------------------------
Message: 3
Date: Wed, 28 Nov 2012 08:00:36 -0800
From: KC <[email protected]>
Subject: Re: [Haskell-beginners] division / multiplication efficiency
To: [email protected]
Message-ID:
<camlkxynpej0xcjrh-mx16ogtbzxmhj3oqcl_ehktkahxamx...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
This may help on the multiplication versus division question:
http://www.cplusplus.com/forum/general/17811/
--
--
Regards,
KC
------------------------------
Message: 4
Date: Wed, 28 Nov 2012 11:14:55 -0500
From: Michael Orlitzky <[email protected]>
Subject: Re: [Haskell-beginners] division / multiplication efficiency
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
On 11/28/2012 08:02 AM, 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? Is there anything to be gained, following the old adage that
> multiplication is more efficient than division in hardware, from
> something like:
>
This doesn't answer your question, but is an interesting read:
http://stackoverflow.com/questions/12653787/what-optimizations-can-ghc-be-expected-to-perform-reliably
I've seen a lot of surprising stuff come out of the optimizer. If you
really want to know which is faster, try both ways.
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 53, Issue 35
*****************************************