MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Division still cost more than multiplication?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg24290] Re: Division still cost more than multiplication?
  • From: Harald Giese <giese at ifm.uni-hamburg.de>
  • Date: Fri, 7 Jul 2000 00:11:31 -0400 (EDT)
  • Organization: Institut fuer Meereskunde, Universitaet Hamburg
  • References: <8k0tc4$q2o@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

AES wrote:
> 
> Old-time FORTRAN programmers (like me) were taught (at least in early
> days) that division cost a lot more machine cycles than multiplication.
> So, if you had an expression like  y = x/c  that was going to be called
> many times inside a loop, where x and y were variables and c a constant,
> you'd code this as:
> 
>    (Outside the loop)
> 
>       cInverse = 1/c;
> 
>    (Begin loop structure)
> 
>       y = cInverse * x
> 
> Does this still make any sense in Mathematica?  Or is it a primitive
> relic of long-gone days?


Hi, 

Just check it:

c = 7.7; cInv = 1./c;

Timing[Do[y = x/c, {x, 0, 10000}]]
{0.631 Second, Null}

Timing[Do[y = x*cInv, {x, 0, 10000}]]
{0.34 Second, Null}


/Harald

-- 

Harald Giese
Email: giese at dkrz.de
Phone: +49 (0)40 42838 5796; Fax: +49 (0)40 5605724
Institut fuer Meereskunde der Universitaet Hamburg
(Institute of Oceanography of the University of Hamburg)
Troplowitzstrasse 7, D-22529 Hamburg


  • Prev by Date: Mathematica gives bad integral ??
  • Next by Date: Re: How to use BestFitParameters?
  • Previous by thread: Re: Division still cost more than multiplication?
  • Next by thread: Re: Division still cost more than multiplication?