MathGroup Archive 2005

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

Search the Archive

Re: Vectorization

  • To: mathgroup at smc.vnet.net
  • Subject: [mg60671] Re: [mg60623] Vectorization
  • From: Zhengji Li <zhengji.li at gmail.com>
  • Date: Fri, 23 Sep 2005 04:20:41 -0400 (EDT)
  • References: <200509220608.CAA01888@smc.vnet.net>
  • Reply-to: Zhengji Li <zhengji.li at gmail.com>
  • Sender: owner-wri-mathgroup at wolfram.com

Marcelo,

That's because the construction of the LONG complex vector uses far
more time than long real vector.

To simplify the matter, just throw Sin away:
Table[I Random[], {1000000}] // Timing // First
I Table[I Random[], {1000000}] // Timing // First
1.983 Second, 3.786 Second.

The frist one is the contruction ONE complex vector, while in the
second one another vector is contructed due to the I * {...}
operation. And 3.786 Second is about 2 * 1.983 Second.

As a comparision,
Table[Random[], {1000000}] // Timing // First
2 Table[Random[], {1000000}] // Timing // First
0.29 Second, 0.411 Second.

In your example,
Table[Sin[I Random[]],{1000000}]//Timing//First
will generate only one complex vector, while
Sin[Table[I Random[],{1000000}]]//Timing//First
will generate two complex vectors. ----- The time saved by
vectorization is less than that used by the contruction of a complex
vector.

--
Li Zhengji
-------------------------------------------------------------
If all you have is a hammer, everything is a nail.
-------------------------------------------------------------


  • References:
  • Prev by Date: Importing part of a WAV file
  • Next by Date: Re: Vectorization
  • Previous by thread: Vectorization
  • Next by thread: Re: Vectorization