MathGroup Archive 2005

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

Search the Archive

Re: Vectorization

  • To: mathgroup at smc.vnet.net
  • Subject: [mg60668] Re: Vectorization
  • From: Peter Pein <petsie at dordos.net>
  • Date: Fri, 23 Sep 2005 04:20:24 -0400 (EDT)
  • References: <dgtjh4$2bk$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Marcelo Mayall schrieb:
> It's possible to initialize a vector starting from an elementary functions:
> 
> In[1]:=
> Table[Sin[Random[]],{10000000}]//Timing//First
> 
> Out[1]=
> 3.203 Second
> 
> The same problem can be done a bit more efficiently if the elementary function is applied to the numerical vector:
> 
> In[2]:=
> Sin[Table[Random[],{10000000}]]//Timing//First
> 
> Out[2]=
> 1.969 Second
> 
> But why the tendency is opposed when the numbers are complex ? Is this a bug ?
> 
> In[3]:=
> Table[Sin[I Random[]],{1000000}]//Timing//First
> Sin[Table[I Random[],{1000000}]]//Timing//First
> 
> Out[3]=
> 2.484 Second
> 
> Out[4]=
> 2.656 Second
> 
> 
> Thanks,
> 
> Marcelo Mayall
> 
Hi Marcelo,

I guess in Sin[Table[I Random[],{10^6}]] the kernel has to decide a
million times to calculate I*Sinh[Im[I*random number]] vs. once in
Table[Sin[I Random[]],{10^6}]?

In[1]:=
SeedRandom[1]; First[Timing[Table[I*Sinh[Random[]], {10^6}]]]
MaxMemoryUsed[]/1024.^2
Out[1]=
  1.734*Second
Out[2]=
  56.998374938964844

<new kernel start>

In[1]:= SeedRandom[1];
First[Timing[I*Sinh[Table[Random[], {10^6}]]]]
MaxMemoryUsed[]/1024.^2
Out[1]=
  1.078*Second
Out[2]=
  110.40516662597656

to compare the timings, here are the results of the four operations from
your posting:

3.125*Second /  ~ 79 MB
2.609*Second / ~ 155 MB
2.094*Second /  ~ 57 MB
2.266*Second / ~ 129 MB

Obviously, the calculation of the sines of lists doesn't happen in-place
(and it must not in general).

Peter

-- 
Peter Pein, Berlin
GnuPG Key ID: 0xA34C5A82
http://people.freenet.de/Peter_Berlin/


  • Prev by Date: Re: Vectorization
  • Next by Date: Re: Generate polynomial of specified degree
  • Previous by thread: Re: Vectorization
  • Next by thread: Re:Re: Vectorization