MathGroup Archive 2005

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

Search the Archive

Re: Timing of looping operators

  • To: mathgroup at smc.vnet.net
  • Subject: [mg62449] Re: Timing of looping operators
  • From: carlos at colorado.edu
  • Date: Thu, 24 Nov 2005 06:33:49 -0500 (EST)
  • References: <200511230931.EAA20248@smc.vnet.net><dm1jrq$n55$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

The difference can be striking for built-in functions,
e.g. the dot product:

n=1000000;  a=b=Table[N[i],{i,n}];
Print[Timing[a.b]];
Print[Timing[Sum[a[[i]]*b[[i]],{i,n}]]];
Print[Timing[s=0; For[i=1,i<=n,i++,s+=a[[i]]*b[[i]]] ]];
Print[Timing[s=0; Do[s+=a[[i]]*b[[i]],{i,n}] ]];

Times:   0.03,  13.2,  28.4,  19.9  sec


  • Prev by Date: Re: Timing of looping operators
  • Next by Date: Re: Error code -43
  • Previous by thread: Re: Timing of looping operators
  • Next by thread: Re: Timing of looping operators